1cbd624adSopenharmony_ciminimal-lexical 2cbd624adSopenharmony_ci=============== 3cbd624adSopenharmony_ci 4cbd624adSopenharmony_ciThis is a minimal version of [rust-lexical](https://github.com/Alexhuszagh/rust-lexical), meant to allow efficient round-trip float parsing. minimal-lexical implements a correct, fast float parser. 5cbd624adSopenharmony_ci 6cbd624adSopenharmony_ciDue to the small, stable nature of minimal-lexical, it is also well-adapted to private forks. If you do privately fork minimal-lexical, I recommend you contact me via [email](mailto:ahuszagh@gmail.com) or [Twitter](https://twitter.com/KardOnIce), so I can notify you of feature updates, bug fixes, or security vulnerabilities, as well as help you implement custom feature requests. I will not use your information for any other purpose, including, but not limited to disclosing your project or organization's use of minimal-lexical. 7cbd624adSopenharmony_ci 8cbd624adSopenharmony_ciminimal-lexical is designed for fast compile times and small binaries sizes, at the expense of a minor amount of performance. For improved performance, feel free to fork minimal-lexical with more aggressive inlining. 9cbd624adSopenharmony_ci 10cbd624adSopenharmony_ci**Similar Projects** 11cbd624adSopenharmony_ci 12cbd624adSopenharmony_ciFor a high-level, all-in-one number conversion routines, see [rust-lexical](https://github.com/Alexhuszagh/rust-lexical). 13cbd624adSopenharmony_ci 14cbd624adSopenharmony_ci**Table Of Contents** 15cbd624adSopenharmony_ci 16cbd624adSopenharmony_ci- [Getting Started](#getting-started) 17cbd624adSopenharmony_ci- [Recipes](#recipes) 18cbd624adSopenharmony_ci- [Algorithms](#algorithms) 19cbd624adSopenharmony_ci- [Platform Support](platform-support) 20cbd624adSopenharmony_ci- [Minimum Version Support](minimum-version-support) 21cbd624adSopenharmony_ci- [Changelog](#changelog) 22cbd624adSopenharmony_ci- [License](#license) 23cbd624adSopenharmony_ci- [Contributing](#contributing) 24cbd624adSopenharmony_ci 25cbd624adSopenharmony_ci# Getting Started 26cbd624adSopenharmony_ci 27cbd624adSopenharmony_ciFirst, add the following to your `Cargo.toml`. 28cbd624adSopenharmony_ci 29cbd624adSopenharmony_ci```toml 30cbd624adSopenharmony_ci[dependencies] 31cbd624adSopenharmony_ciminimal-lexical = "0.2" 32cbd624adSopenharmony_ci``` 33cbd624adSopenharmony_ci 34cbd624adSopenharmony_ciNext, to parse a simple float, use the following: 35cbd624adSopenharmony_ci 36cbd624adSopenharmony_ci```rust 37cbd624adSopenharmony_ciextern crate minimal_lexical; 38cbd624adSopenharmony_ci 39cbd624adSopenharmony_ci// Let's say we want to parse "1.2345". 40cbd624adSopenharmony_ci// First, we need an external parser to extract the integer digits ("1"), 41cbd624adSopenharmony_ci// the fraction digits ("2345"), and then parse the exponent to a 32-bit 42cbd624adSopenharmony_ci// integer (0). 43cbd624adSopenharmony_ci// Warning: 44cbd624adSopenharmony_ci// -------- 45cbd624adSopenharmony_ci// Please note that leading zeros must be trimmed from the integer, 46cbd624adSopenharmony_ci// and trailing zeros must be trimmed from the fraction. This cannot 47cbd624adSopenharmony_ci// be handled by minimal-lexical, since we accept iterators 48cbd624adSopenharmony_cilet integer = b"1"; 49cbd624adSopenharmony_cilet fraction = b"2345"; 50cbd624adSopenharmony_cilet float: f64 = minimal_lexical::parse_float(integer.iter(), fraction.iter(), 0); 51cbd624adSopenharmony_ciprintln!("float={:?}", float); // 1.235 52cbd624adSopenharmony_ci``` 53cbd624adSopenharmony_ci 54cbd624adSopenharmony_ci# Recipes 55cbd624adSopenharmony_ci 56cbd624adSopenharmony_ciYou may be asking: where is the actual parser? Due to variation in float formats, and the goal of integrating utility for various data-interchange language parsers, such functionality would be beyond the scope of this library. 57cbd624adSopenharmony_ci 58cbd624adSopenharmony_ciFor example, the following float is valid in Rust strings, but is invalid in JSON or TOML: 59cbd624adSopenharmony_ci```json 60cbd624adSopenharmony_ci1.e7 61cbd624adSopenharmony_ci``` 62cbd624adSopenharmony_ci 63cbd624adSopenharmony_ciTherefore, to use the library, you need functionality that extracts the significant digits to pass to `create_float`. Please see [simple-example](https://github.com/Alexhuszagh/minimal-lexical/blob/master/examples/simple.rs) for a simple, annotated example on how to use minimal-lexical as a parser. 64cbd624adSopenharmony_ci 65cbd624adSopenharmony_ci# Algorithms 66cbd624adSopenharmony_ci 67cbd624adSopenharmony_ciFor an in-depth explanation on the algorithms minimal-lexical uses, please see [lexical-core#string-to-float](https://github.com/Alexhuszagh/rust-lexical/tree/master/lexical-core#string-to-float). 68cbd624adSopenharmony_ci 69cbd624adSopenharmony_ci# Platform Support 70cbd624adSopenharmony_ci 71cbd624adSopenharmony_ciminimal-lexical is tested on a wide variety of platforms, including big and small-endian systems, to ensure portable code. Supported architectures include: 72cbd624adSopenharmony_ci- x86_64 Linux, Windows, macOS, Android, iOS, FreeBSD, and NetBSD. 73cbd624adSopenharmony_ci- x86 Linux, macOS, Android, iOS, and FreeBSD. 74cbd624adSopenharmony_ci- aarch64 (ARM8v8-A) Linux, Android, and iOS. 75cbd624adSopenharmony_ci- armv7 (ARMv7-A) Linux, Android, and iOS. 76cbd624adSopenharmony_ci- arm (ARMv6) Linux, and Android. 77cbd624adSopenharmony_ci- mips (MIPS) Linux. 78cbd624adSopenharmony_ci- mipsel (MIPS LE) Linux. 79cbd624adSopenharmony_ci- mips64 (MIPS64 BE) Linux. 80cbd624adSopenharmony_ci- mips64el (MIPS64 LE) Linux. 81cbd624adSopenharmony_ci- powerpc (PowerPC) Linux. 82cbd624adSopenharmony_ci- powerpc64 (PPC64) Linux. 83cbd624adSopenharmony_ci- powerpc64le (PPC64LE) Linux. 84cbd624adSopenharmony_ci- s390x (IBM Z) Linux. 85cbd624adSopenharmony_ci 86cbd624adSopenharmony_ciminimal-lexical should also work on a wide variety of other architectures and ISAs. If you have any issue compiling minimal-lexical on any architecture, please file a bug report. 87cbd624adSopenharmony_ci 88cbd624adSopenharmony_ci# Minimum Version Support 89cbd624adSopenharmony_ci 90cbd624adSopenharmony_ciMinimal-lexical is tested to support Rustc 1.36+, including stable, beta, and nightly. Please report any errors compiling a supported lexical version on a compatible Rustc version. Please note we may increment the MSRV for compiler versions older than 18 months, to support at least the current Debian stable version, without breaking changes. 91cbd624adSopenharmony_ci 92cbd624adSopenharmony_ci# Changelog 93cbd624adSopenharmony_ci 94cbd624adSopenharmony_ciAll changes are documented in [CHANGELOG](CHANGELOG). 95cbd624adSopenharmony_ci 96cbd624adSopenharmony_ci# License 97cbd624adSopenharmony_ci 98cbd624adSopenharmony_ciMinimal-lexical is dual licensed under the Apache 2.0 license as well as the MIT license. See the [LICENSE.md](LICENSE.md) file for full license details. 99cbd624adSopenharmony_ci 100cbd624adSopenharmony_ci# Contributing 101cbd624adSopenharmony_ci 102cbd624adSopenharmony_ciUnless you explicitly state otherwise, any contribution intentionally submitted for inclusion in minimal-lexical by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions. 103