ryu/lib.rs
1//! Pure Rust implementation of Ryū, an algorithm to quickly convert floating
2//! point numbers to decimal strings.
3//!
4//! # Example
5//!
6//! ```
7//! fn main() {
8//! let mut buffer = ryu::Buffer::new();
9//! let printed = buffer.format(1.234);
10//! assert_eq!(printed, "1.234");
11//! }
12//! ```
13//!
14//! ## Performance (lower is better)
15//!
16//! The upstream C code, the unsafe direct Rust port, and the safe pretty Rust
17//! API all perform the same, taking around 21 nanoseconds to format a 32-bit
18//! float and 31 nanoseconds to format a 64-bit float.
19//!
20//! Ryū is approximately 2-5x faster than the standard library across a range
21//! of f32 and f64 inputs. Measurements are in nanoseconds per iteration;
22//! smaller is better.
23//!
24//! ## Formatting
25//!
26//! This library tends to produce more human-readable output than the standard
27//! library's to\_string, which never uses scientific notation. Here are two
28//! examples:
29//!
30//! - *ryu:* 1.23e40, *std:* 12300000000000000000000000000000000000000
31//! - *ryu:* 1.23e-40, *std:* 0.000000000000000000000000000000000000000123
32//!
33//! Both libraries print short decimals such as 0.0000123 without scientific
34//! notation.
35
36#![no_std]
37#![allow(
38 clippy::cast_lossless,
39 clippy::cast_possible_truncation,
40 clippy::cast_possible_wrap,
41 clippy::cast_sign_loss,
42 clippy::checked_conversions,
43 clippy::doc_markdown,
44 clippy::expl_impl_clone_on_copy,
45 clippy::if_not_else,
46 clippy::many_single_char_names,
47 clippy::missing_panics_doc,
48 clippy::module_name_repetitions,
49 clippy::must_use_candidate,
50 clippy::needless_doctest_main,
51 clippy::similar_names,
52 clippy::too_many_lines,
53 clippy::unreadable_literal,
54 clippy::unseparated_literal_suffix,
55 clippy::wildcard_imports
56)]
57
58mod buffer;
59mod common;
60mod d2s;
61#[cfg(not(feature = "small"))]
62mod d2s_full_table;
63mod d2s_intrinsics;
64#[cfg(feature = "small")]
65mod d2s_small_table;
66mod digit_table;
67mod f2s;
68mod f2s_intrinsics;
69mod pretty;
70
71pub use crate::buffer::{Buffer, Float};
72
73/// Unsafe functions that mirror the API of the C implementation of Ryū.
74pub mod raw {
75 pub use crate::pretty::{format32, format64};
76}