Function hex_uint

fn hex_uint<Input, Output, Error>(input: &mut Input) -> Result<Output, Error>
where
    Input: StreamIsPartial + Stream,
    <Input as Stream>::Token: AsChar,
    <Input as Stream>::Slice: AsBStr,
    Output: HexUint,
    Error: ParserError<Input>

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][crate::_topic::partial]: Will return Err(winnow::error::ErrMode::Incomplete(_)) if end-of-input is hit before a hard boundary (non-hex character, more characters than supported).

Effective Signature

Assuming you are parsing a &str [Stream] into a u32:

# use winnow::prelude::*;;
pub fn hex_uint(input: &mut &str) -> ModalResult<u32>
# {
#     winnow::ascii::hex_uint.parse_next(input)
# }

Example

# use winnow::prelude::*;
use winnow::ascii::hex_uint;

fn parser<'s>(s: &mut &'s [u8]) -> ModalResult<u32> {
  hex_uint(s)
}

assert_eq!(parser.parse_peek(&b"01AE"[..]), Ok((&b""[..], 0x01AE)));
assert_eq!(parser.parse_peek(&b"abc"[..]), Ok((&b""[..], 0x0ABC)));
assert!(parser.parse_peek(&b"ggg"[..]).is_err());
# use winnow::prelude::*;
# use winnow::{error::ErrMode, error::Needed};
# use winnow::Partial;
use winnow::ascii::hex_uint;

fn parser<'s>(s: &mut Partial<&'s [u8]>) -> ModalResult<u32> {
  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!(parser.parse_peek(Partial::new(&b"ggg"[..])).is_err());