Function nom8::character::f64

source ·
pub fn f64<T, E: ParseError<T>, const STREAMING: bool>(
    input: T
) -> IResult<T, f64, E>where
    T: Slice<RangeFrom<usize>> + Slice<RangeTo<usize>> + Slice<Range<usize>> + Clone + Offset + Compare<&'static str> + InputIter + InputLength + InputTake + InputIsStreaming<STREAMING> + IntoOutput + InputTakeAtPosition + AsBytes + for<'a> Compare<&'a [u8]>,
    <T as IntoOutput>::Output: ParseTo<f64>,
    <T as InputIter>::Item: AsChar + Copy,
    <T as InputIter>::IterElem: Clone,
    <T as InputTakeAtPosition>::Item: AsChar,
Expand description

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

Complete version: Can parse until the end of input.

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

Example

use nom8::character::f64;

let parser = |s| {
  f64(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))));
use nom8::character::f64;

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

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