Function nom::character::complete::char

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

Recognizes one character.

Complete version: Will return an error if there’s not enough input data.

Example

fn parser(i: &str) -> IResult<&str, char> {
    char('a')(i)
}
assert_eq!(parser("abc"), Ok(("bc", 'a')));
assert_eq!(parser(" abc"), Err(Err::Error(Error::new(" abc", ErrorKind::Char))));
assert_eq!(parser("bc"), Err(Err::Error(Error::new("bc", ErrorKind::Char))));
assert_eq!(parser(""), Err(Err::Error(Error::new("", ErrorKind::Char))));