| 1 |
//! Fast, minimal float-parsing algorithm. |
| 2 |
//! |
| 3 |
//! minimal-lexical has a simple, high-level API with a single |
| 4 |
//! exported function: [`parse_float`]. |
| 5 |
//! |
| 6 |
//! [`parse_float`] expects a forward iterator for the integer |
| 7 |
//! and fraction digits, as well as a parsed exponent as an [`i32`]. |
| 8 |
//! |
| 9 |
//! For more examples, please see [simple-example](https://github.com/Alexhuszagh/minimal-lexical/blob/master/examples/simple.rs). |
| 10 |
//! |
| 11 |
//! EXAMPLES |
| 12 |
//! -------- |
| 13 |
//! |
| 14 |
//! ``` |
| 15 |
//! extern crate minimal_lexical; |
| 16 |
//! |
| 17 |
//! // Let's say we want to parse "1.2345". |
| 18 |
//! // First, we need an external parser to extract the integer digits ("1"), |
| 19 |
//! // the fraction digits ("2345"), and then parse the exponent to a 32-bit |
| 20 |
//! // integer (0). |
| 21 |
//! // Warning: |
| 22 |
//! // -------- |
| 23 |
//! // Please note that leading zeros must be trimmed from the integer, |
| 24 |
//! // and trailing zeros must be trimmed from the fraction. This cannot |
| 25 |
//! // be handled by minimal-lexical, since we accept iterators. |
| 26 |
//! let integer = b"1"; |
| 27 |
//! let fraction = b"2345"; |
| 28 |
//! let float: f64 = minimal_lexical::parse_float(integer.iter(), fraction.iter(), 0); |
| 29 |
//! println!("float={:?}", float); // 1.235 |
| 30 |
//! ``` |
| 31 |
//! |
| 32 |
//! [`parse_float`]: fn.parse_float.html |
| 33 |
//! [`i32`]: https://doc.rust-lang.org/stable/std/primitive.i32.html |
| 34 |
|
| 35 |
// FEATURES |
| 36 |
|
| 37 |
// We want to have the same safety guarantees as Rust core, |
| 38 |
// so we allow unused unsafe to clearly document safety guarantees. |
| 39 |
#![allow(unused_unsafe)] |
| 40 |
#![cfg_attr(feature = "lint", warn(unsafe_op_in_unsafe_fn))] |
| 41 |
#![cfg_attr(not(feature = "std"), no_std)] |
| 42 |
|
| 43 |
#[cfg(all(feature = "alloc", not(feature = "std")))] |
| 44 |
extern crate alloc; |
| 45 |
|
| 46 |
pub mod bellerophon; |
| 47 |
pub mod bigint; |
| 48 |
pub mod extended_float; |
| 49 |
pub mod fpu; |
| 50 |
pub mod heapvec; |
| 51 |
pub mod lemire; |
| 52 |
pub mod libm; |
| 53 |
pub mod mask; |
| 54 |
pub mod num; |
| 55 |
pub mod number; |
| 56 |
pub mod parse; |
| 57 |
pub mod rounding; |
| 58 |
pub mod slow; |
| 59 |
pub mod stackvec; |
| 60 |
pub mod table; |
| 61 |
|
| 62 |
mod table_bellerophon; |
| 63 |
mod table_lemire; |
| 64 |
mod table_small; |
| 65 |
|
| 66 |
// API |
| 67 |
pub use self::num::Float; |
| 68 |
pub use self::parse::parse_float; |