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

Function f64

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

Recognizes an 8 byte floating point number

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

use nom::number::complete::f64;

let be_f64 = |s| {
  f64(nom::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(Err::Error((&b"abc"[..], ErrorKind::Eof))));

let le_f64 = |s| {
  f64(nom::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(Err::Error((&b"abc"[..], ErrorKind::Eof))));