pub fn verify<I, O1, O2, E, F, G>(first: F, second: G) -> impl FnMut(I)
Available on crate feature
mtls
only.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.
use nom::combinator::verify;
use nom::character::complete::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))));