Function nom8::number::streaming::float

source ·
pub fn float<T, E: ParseError<T>>(input: T) -> IResult<T, f32, E>where
    T: Slice<RangeFrom<usize>> + Slice<RangeTo<usize>> + Clone + Offset + InputIter + InputLength + InputTake + Compare<&'static str> + IntoOutput + InputTakeAtPosition + AsBytes + for<'a> Compare<&'a [u8]>,
    <T as IntoOutput>::Output: ParseTo<f32>,
    <T as InputIter>::Item: AsChar,
    <T as InputIter>::IterElem: Clone,
    <T as InputTakeAtPosition>::Item: AsChar,
👎Deprecated since 8.0.0: Replaced with nom8::character::f32 with input wrapped in nom8::input::Streaming
Expand description

Recognizes floating point number in text format and returns a f32.

Streaming version: Will return Err(nom8::Err::Incomplete(_)) if there is not enough data.

use nom8::number::complete::float;

let parser = |s| {
  float(s)
};

assert_eq!(parser("11e-1"), Ok(("", 1.1)));
assert_eq!(parser("123E-02"), Ok(("", 1.23)));
assert_eq!(parser("123K-01"), Ok(("K-01", 123.0)));
assert_eq!(parser("abc"), Err(Err::Error(("abc", ErrorKind::Float))));

WARNING: Deprecated, replaced with nom8::character::f32 with input wrapped in nom8::input::Streaming