winnow::ascii

Function hex_digit1

Source
pub fn hex_digit1<Input, Error>(
    input: &mut Input,
) -> Result<<Input as Stream>::Slice, Error>
where Input: StreamIsPartial + Stream, <Input as Stream>::Token: AsChar, Error: ParserError<Input>,
Expand description

Recognizes one or more ASCII hexadecimal numerical characters: '0'..='9', 'A'..='F', 'a'..='f'

Complete version: Will return an error if there’s not enough input data, or the whole input if no terminating token is found (a non hexadecimal digit character).

[Partial version][crate::_topic::partial]: Will return Err(winnow::error::ErrMode::Incomplete(_)) if there’s not enough input data, or if no terminating token is found (a non hexadecimal digit character).

§Effective Signature

Assuming you are parsing a &str Stream:

pub fn hex_digit1<'i>(input: &mut &'i str) -> ModalResult<&'i str>

§Example

fn parser<'s>(input: &mut &'s str) -> ModalResult<&'s str> {
    hex_digit1.parse_next(input)
}

assert_eq!(parser.parse_peek("21cZ"), Ok(("Z", "21c")));
assert!(parser.parse_peek("H2").is_err());
assert!(parser.parse_peek("").is_err());
assert_eq!(hex_digit1::<_, ErrMode<ContextError>>.parse_peek(Partial::new("21cZ")), Ok((Partial::new("Z"), "21c")));
assert!(hex_digit1::<_, ErrMode<ContextError>>.parse_peek(Partial::new("H2")).is_err());
assert_eq!(hex_digit1::<_, ErrMode<ContextError>>.parse_peek(Partial::new("")), Err(ErrMode::Incomplete(Needed::new(1))));