rocket::mtls::oid::asn1_rs::nom::number::streaming

Function hex_u32

Source
pub fn hex_u32<'a, E>(input: &'a [u8]) -> Result<(&'a [u8], u32), Err<E>>
where E: ParseError<&'a [u8]>,
Available on crate feature mtls only.
Expand description

Recognizes a hex-encoded integer.

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

use nom::number::streaming::hex_u32;

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

assert_eq!(parser(b"01AE;"), Ok((&b";"[..], 0x01AE)));
assert_eq!(parser(b"abc"), Err(Err::Incomplete(Needed::new(1))));
assert_eq!(parser(b"ggg"), Err(Err::Error((&b"ggg"[..], ErrorKind::IsA))));