lexical_write_integer/
lib.rs

1//! Fast lexical integer-to-string conversion routines.
2//!
3//! The default implementations use power reduction to unroll
4//! 4 loops at a time to minimize the number of required divisions,
5//! leading to massive performance gains. In addition, decimal
6//! strings pre-calculate the number of digits, avoiding temporary buffers.
7//!
8//! A compact, fallback algorithm uses a naive, simple algorithm,
9//! where each loop generates a single digit. This comes at a performance
10//! penalty, but produces smaller binaries.
11//!
12//! # Features
13//!
14//! * `std` - Use the standard library.
15//! * `power-of-two` - Add support for writing power-of-two integer strings.
16//! * `radix` - Add support for strings of any radix.
17//! * `compact` - Reduce code size at the cost of performance.
18//! * `safe` - Ensure only memory-safe indexing is used.
19//!
20//! # Note
21//!
22//! Only documented functionality is considered part of the public API:
23//! any of the modules, internal functions, or structs may change
24//! release-to-release without major or minor version changes. Use
25//! internal implementation details at your own risk.
26//!
27//! lexical-write-integer mainly exists as an implementation detail for
28//! lexical-core, although its API is stable. If you would like to use
29//! a high-level API that writes to and parses from `String` and `&str`,
30//! respectively, please look at [lexical](https://crates.io/crates/lexical)
31//! instead. If you would like an API that supports multiple numeric
32//! conversions, please look at [lexical-core](https://crates.io/crates/lexical-core)
33//! instead.
34//!
35//! # Version Support
36//!
37//! The minimum, standard, required version is 1.51.0, for const generic
38//! support. Older versions of lexical support older Rust versions.
39//!
40//! # Design
41//!
42//! - [Algorithm Approach](https://github.com/Alexhuszagh/rust-lexical/blob/main/lexical-write-integer/docs/Algorithm.md)
43//! - [Benchmarks](https://github.com/Alexhuszagh/rust-lexical/blob/main/lexical-write-integer/docs/Benchmarks.md)
44
45// We want to have the same safety guarantees as Rust core,
46// so we allow unused unsafe to clearly document safety guarantees.
47#![allow(unused_unsafe)]
48#![cfg_attr(feature = "lint", warn(unsafe_op_in_unsafe_fn))]
49#![cfg_attr(not(feature = "std"), no_std)]
50
51#[macro_use]
52mod index;
53
54pub mod algorithm;
55pub mod compact;
56pub mod decimal;
57pub mod options;
58pub mod radix;
59pub mod table;
60pub mod write;
61
62mod api;
63mod table_binary;
64mod table_decimal;
65mod table_radix;
66
67// Re-exports
68pub use self::api::{ToLexical, ToLexicalWithOptions};
69#[doc(inline)]
70pub use self::options::{Options, OptionsBuilder};
71pub use lexical_util::constants::{FormattedSize, BUFFER_SIZE};
72pub use lexical_util::format::{self, NumberFormatBuilder};
73pub use lexical_util::options::WriteOptions;