Function nom8::character::digit0

source ·
pub fn digit0<T, E: ParseError<T>, const STREAMING: bool>(
    input: T
) -> IResult<T, <T as IntoOutput>::Output, E>where
    T: InputTakeAtPosition + InputIsStreaming<STREAMING> + IntoOutput,
    <T as InputTakeAtPosition>::Item: 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).

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

Example

fn parser(input: &str) -> IResult<&str, &str> {
    digit0(input)
}

assert_eq!(parser("21c"), Ok(("c", "21")));
assert_eq!(parser("21"), Ok(("", "21")));
assert_eq!(parser("a21c"), Ok(("a21c", "")));
assert_eq!(parser(""), Ok(("", "")));
assert_eq!(digit0::<_, (_, ErrorKind), true>(Streaming("21c")), Ok((Streaming("c"), "21")));
assert_eq!(digit0::<_, (_, ErrorKind), true>(Streaming("a21c")), Ok((Streaming("a21c"), "")));
assert_eq!(digit0::<_, (_, ErrorKind), true>(Streaming("")), Err(Err::Incomplete(Needed::new(1))));