Function nom::combinator::value
source ยท pub fn value<I, O1: Clone, O2, E: ParseError<I>, F>(
val: O1,
parser: F,
) -> impl FnMut(I) -> IResult<I, O1, E>where
F: Parser<I, O2, E>,
Expand description
Returns the provided value if the child parser succeeds.
use nom::combinator::value;
use nom::character::complete::alpha1;
let mut parser = value(1234, alpha1);
assert_eq!(parser("abcd"), Ok(("", 1234)));
assert_eq!(parser("123abcd;"), Err(Err::Error(("123abcd;", ErrorKind::Alpha))));