Function digit0

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

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

Effective Signature

Assuming you are parsing a &str [Stream]:

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

Example

# use winnow::prelude::*;
# use winnow::ascii::digit0;
fn parser<'s>(input: &mut &'s str) -> ModalResult<&'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(("", "")));
# use winnow::prelude::*;
# use winnow::{error::ErrMode, error::ContextError, error::Needed};
# use winnow::Partial;
# use winnow::ascii::digit0;
assert_eq!(digit0::<_, ErrMode<ContextError>>.parse_peek(Partial::new("21c")), Ok((Partial::new("c"), "21")));
assert_eq!(digit0::<_, ErrMode<ContextError>>.parse_peek(Partial::new("a21c")), Ok((Partial::new("a21c"), "")));
assert_eq!(digit0::<_, ErrMode<ContextError>>.parse_peek(Partial::new("")), Err(ErrMode::Incomplete(Needed::new(1))));