Function rocket::mtls::x509::der_parser::asn1_rs::nom::combinator::success
source ยท pub fn success<I, O, E>(val: O) -> impl Fn(I)where
O: Clone,
E: ParseError<I>,
Available on crate feature
mtls
only.Expand description
a parser which always succeeds with given value without consuming any input.
It can be used for example as the last alternative in alt
to
specify the default case.
use nom::branch::alt;
use nom::combinator::{success, value};
use nom::character::complete::char;
let mut parser = success::<_,_,(_,ErrorKind)>(10);
assert_eq!(parser("xyz"), Ok(("xyz", 10)));
let mut sign = alt((value(-1, char('-')), value(1, char('+')), success::<_,_,(_,ErrorKind)>(1)));
assert_eq!(sign("+10"), Ok(("10", 1)));
assert_eq!(sign("-10"), Ok(("10", -1)));
assert_eq!(sign("10"), Ok(("10", 1)));