rustmax::nom::number::complete

Function hex_u32

Source
pub fn hex_u32<I, E>(input: I) -> Result<(I, u32), Err<E>>
where E: ParseError<I>, I: Input + AsBytes, <I as Input>::Item: AsChar,
Expand description

Recognizes a hex-encoded integer.

Complete version: Will parse until the end of input if it has less than 8 bytes.

use nom::number::complete::hex_u32;

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

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