Function winnow::ascii::digit0

source ·
pub fn digit0<I, E: ParserError<I>>(
    input: &mut I,
) -> PResult<<I as Stream>::Slice, E>
where I: StreamIsPartial + Stream, <I as Stream>::Token: AsChar,
Expand description

Recognizes zero or more ASCII numerical characters: '0'..='9'

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 digit character).

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

§Example

fn parser<'s>(input: &mut &'s str) -> PResult<&'s str, InputError<&'s str>> {
    digit0.parse_next(input)
}

assert_eq!(parser.parse_peek("21c"), Ok(("c", "21")));
assert_eq!(parser.parse_peek("21"), Ok(("", "21")));
assert_eq!(parser.parse_peek("a21c"), Ok(("a21c", "")));
assert_eq!(parser.parse_peek(""), Ok(("", "")));
assert_eq!(digit0::<_, InputError<_>>.parse_peek(Partial::new("21c")), Ok((Partial::new("c"), "21")));
assert_eq!(digit0::<_, InputError<_>>.parse_peek(Partial::new("a21c")), Ok((Partial::new("a21c"), "")));
assert_eq!(digit0::<_, InputError<_>>.parse_peek(Partial::new("")), Err(ErrMode::Incomplete(Needed::new(1))));