Function rocket::mtls::oid::asn1_rs::nom::number::complete::f32

pub fn f32<I, E>(endian: Endianness) -> fn(_: I) -> Result<(I, f32), Err<E>>
where E: ParseError<I>, I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
Available on crate feature mtls only.
Expand description

Recognizes a 4 byte floating point number

If the parameter is nom::number::Endianness::Big, parse a big endian f32 float, otherwise if nom::number::Endianness::Little parse a little endian f32 float. complete version: returns an error if there is not enough input data

use nom::number::complete::f32;

let be_f32 = |s| {
  f32(nom::number::Endianness::Big)(s)
};

assert_eq!(be_f32(&[0x41, 0x48, 0x00, 0x00][..]), Ok((&b""[..], 12.5)));
assert_eq!(be_f32(&b"abc"[..]), Err(Err::Error((&b"abc"[..], ErrorKind::Eof))));

let le_f32 = |s| {
  f32(nom::number::Endianness::Little)(s)
};

assert_eq!(le_f32(&[0x00, 0x00, 0x48, 0x41][..]), Ok((&b""[..], 12.5)));
assert_eq!(le_f32(&b"abc"[..]), Err(Err::Error((&b"abc"[..], ErrorKind::Eof))));