Function winnow::number::streaming::f64

source ·
pub fn f64<I, E: ParseError<I>>(
    endian: Endianness
) -> fn(_: I) -> IResult<I, f64, E>where
    I: Stream<Token = u8>,
    <I as Stream>::Slice: AsBytes,
👎Deprecated since 0.1.0: Replaced with <code>winnow::number::f64</code> with input wrapped in <code>winnow::Partial</code>
Expand description

Recognizes an 8 byte floating point number

If the parameter is winnow::number::Endianness::Big, parse a big endian f64 float, otherwise if winnow::number::Endianness::Little parse a little endian f64 float. Partial version: Will return Err(winnow::error::ErrMode::Incomplete(_)) if there is not enough data.

use winnow::number::streaming::f64;

let be_f64 = |s| {
  f64::<_, Error<_>>(winnow::number::Endianness::Big)(s)
};

assert_eq!(be_f64(&[0x40, 0x29, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00][..]), Ok((&b""[..], 12.5)));
assert_eq!(be_f64(&b"abc"[..]), Err(ErrMode::Incomplete(Needed::new(5))));

let le_f64 = |s| {
  f64::<_, Error<_>>(winnow::number::Endianness::Little)(s)
};

assert_eq!(le_f64(&[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x29, 0x40][..]), Ok((&b""[..], 12.5)));
assert_eq!(le_f64(&b"abc"[..]), Err(ErrMode::Incomplete(Needed::new(5))));

WARNING: Deprecated, replaced with winnow::number::f64 with input wrapped in winnow::Partial