pub fn hex_uint<I, O, E: ParserError<I>>(input: &mut I) -> PResult<O, E>
Expand description
Decode a variable-width hexadecimal integer (e.g. u32
)
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::ascii::hex_uint;
fn parser<'s>(s: &mut &'s [u8]) -> PResult<u32, InputError<&'s [u8]>> {
hex_uint(s)
}
assert_eq!(parser.parse_peek(&b"01AE"[..]), Ok((&b""[..], 0x01AE)));
assert_eq!(parser.parse_peek(&b"abc"[..]), Ok((&b""[..], 0x0ABC)));
assert_eq!(parser.parse_peek(&b"ggg"[..]), Err(ErrMode::Backtrack(InputError::new(&b"ggg"[..], ErrorKind::Slice))));
use winnow::ascii::hex_uint;
fn parser<'s>(s: &mut Partial<&'s [u8]>) -> PResult<u32, InputError<Partial<&'s [u8]>>> {
hex_uint(s)
}
assert_eq!(parser.parse_peek(Partial::new(&b"01AE;"[..])), Ok((Partial::new(&b";"[..]), 0x01AE)));
assert_eq!(parser.parse_peek(Partial::new(&b"abc"[..])), Err(ErrMode::Incomplete(Needed::new(1))));
assert_eq!(parser.parse_peek(Partial::new(&b"ggg"[..])), Err(ErrMode::Backtrack(InputError::new(Partial::new(&b"ggg"[..]), ErrorKind::Slice))));