Function winnow::number::streaming::f32

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

Recognizes a 4 byte floating point number

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

use winnow::number::streaming::f32;

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

assert_eq!(be_f32(&[0x41, 0x48, 0x00, 0x00][..]), Ok((&b""[..], 12.5)));
assert_eq!(be_f32(&b"abc"[..]), Err(ErrMode::Incomplete(Needed::new(1))));

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

assert_eq!(le_f32(&[0x00, 0x00, 0x48, 0x41][..]), Ok((&b""[..], 12.5)));
assert_eq!(le_f32(&b"abc"[..]), Err(ErrMode::Incomplete(Needed::new(1))));

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