fast_float - Rust (original) (raw)

Expand description

This crate provides a super-fast decimal number parser from strings into floats.

§Usage

There’s two top-level functions provided: parse andparse_partial, both taking either a string or a bytes slice and parsing the input into either f32 or f64:

§Examples

// Parse the entire string as a decimal number.
let s = "1.23e-02";
let x: f32 = fast_float::parse(s).unwrap();
assert_eq!(x, 0.0123);

// Parse as many characters as possible as a decimal number.
let s = "1.23e-02foo";
let (x, n) = fast_float::parse_partial::<f32, _>(s).unwrap();
assert_eq!(x, 0.0123);
assert_eq!(n, 8);
assert_eq!(&s[n..], "foo");

Error

Opaque error type for fast-float parsing functions.

FastFloat

Trait for numerical float types that can be parsed from string.

parse

Parse a decimal number from string into float (full).

parse_partial

Parse a decimal number from string into float (partial).

Result

Result type alias for fast-float parsing functions.