Function chomp::ascii::float
[−]
[src]
pub fn float<I: Input<Token = u8>, F: Float<I::Buffer>>(
i: I
) -> SimpleResult<I, F>
Parses a float into a f64
or f32
, will error with an Error::unexpected
if the float
does not map to a proper float.
Supports the format /[+-]?[0-9]+(\.[0-9]+)?([eE][+-]?[0-9]+)/
NOTE: Currently requires an allocation due to being generic over Input::Buffer
and
internally Rust's f32
requires a &str
to be able to parse. If the nightly compiler is used
the Float
trait implementation for f32
and f64
will be specialized if the Buffer
is
&[u8]
and will not require an allocation.
use chomp::parse_only; use chomp::ascii::float; assert_eq!(parse_only(float, &b"3.14159265359"[..]), Ok(3.14159265359));