rustmax::nom::character::streaming

Function satisfy

Source
pub fn satisfy<F, I, Error>(cond: F) -> impl FnMut(I)
where Error: ParseError<I>, I: Input, <I as Input>::Item: AsChar, F: Fn(char) -> bool,
Expand description

Recognizes one character and checks that it satisfies a predicate

Streaming version: Will return Err(nom::Err::Incomplete(_)) if there’s not enough input data.

§Example

fn parser(i: &str) -> IResult<&str, char> {
    satisfy(|c| c == 'a' || c == 'b')(i)
}
assert_eq!(parser("abc"), Ok(("bc", 'a')));
assert_eq!(parser("cd"), Err(Err::Error(Error::new("cd", ErrorKind::Satisfy))));
assert_eq!(parser(""), Err(Err::Incomplete(Needed::Unknown)));