pub fn hex_uint<I, O, E: ParseError<I>>(input: I) -> IResult<I, O, E>where
I: StreamIsPartial + Stream,
O: HexUint,
<I as Stream>::Token: AsChar,
<I as Stream>::Slice: AsBStr,
Expand description
Decode a variable-width hexadecimal integer.
Complete version: Will parse until the end of input if it has fewer characters than the type supports.
Partial version: Will return Err(winnow::error::ErrMode::Incomplete(_))
if end-of-input
is hit before a hard boundary (non-hex character, more characters than supported).
Example
use winnow::character::hex_uint;
fn parser(s: &[u8]) -> IResult<&[u8], u32> {
hex_uint(s)
}
assert_eq!(parser(&b"01AE"[..]), Ok((&b""[..], 0x01AE)));
assert_eq!(parser(&b"abc"[..]), Ok((&b""[..], 0x0ABC)));
assert_eq!(parser(&b"ggg"[..]), Err(ErrMode::Backtrack(Error::new(&b"ggg"[..], ErrorKind::Slice))));
use winnow::character::hex_uint;
fn parser(s: Partial<&[u8]>) -> IResult<Partial<&[u8]>, u32> {
hex_uint(s)
}
assert_eq!(parser(Partial::new(&b"01AE;"[..])), Ok((Partial::new(&b";"[..]), 0x01AE)));
assert_eq!(parser(Partial::new(&b"abc"[..])), Err(ErrMode::Incomplete(Needed::new(1))));
assert_eq!(parser(Partial::new(&b"ggg"[..])), Err(ErrMode::Backtrack(Error::new(Partial::new(&b"ggg"[..]), ErrorKind::Slice))));