Function nom8::combinator::verify

source ·
pub fn verify<I: Clone, O1, O2, E: ParseError<I>, F, G>(
    first: F,
    second: G
) -> impl FnMut(I) -> IResult<I, O1, E>where
    F: Parser<I, O1, E>,
    G: Fn(&O2) -> bool,
    O1: Borrow<O2>,
    O2: ?Sized,
👎Deprecated since 8.0.0: Replaced with `Parser::verify
Expand description

Returns the result of the child parser if it satisfies a verification function.

The verification function takes as argument a reference to the output of the parser.

WARNING: Deprecated, replaced with Parser::map

use nom8::combinator::verify;
use nom8::character::alpha1;

let mut parser = verify(alpha1, |s: &str| s.len() == 4);

assert_eq!(parser("abcd"), Ok(("", "abcd")));
assert_eq!(parser("abcde"), Err(Err::Error(("abcde", ErrorKind::Verify))));
assert_eq!(parser("123abcd;"),Err(Err::Error(("123abcd;", ErrorKind::Alpha))));