Function nom::character::complete::satisfy

source ·
pub fn satisfy<F, I, Error: ParseError<I>>(
    cond: F,
) -> impl Fn(I) -> IResult<I, char, Error>
where I: Slice<RangeFrom<usize>> + InputIter, <I as InputIter>::Item: AsChar, F: Fn(char) -> bool,
Expand description

Recognizes one character and checks that it satisfies a predicate

Complete version: Will return an error 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::Error(Error::new("", ErrorKind::Satisfy))));