Function nom8::number::hex_u32

source ·
pub fn hex_u32<I, E: ParseError<I>, const STREAMING: bool>(
    input: I
) -> IResult<I, u32, E>where
    I: InputTakeAtPosition + InputIsStreaming<STREAMING> + Slice<RangeFrom<usize>> + Slice<RangeTo<usize>> + AsBytes + InputLength,
    <I as InputTakeAtPosition>::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.

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

Example

use nom8::number::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))));
use nom8::number::hex_u32;

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

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