Function rocket::mtls::x509::der_parser::asn1_rs::nom::combinator::opt

source ยท
pub fn opt<I, O, E, F>(f: F) -> impl FnMut(I)
where I: Clone, E: ParseError<I>, F: Parser<I, O, E>,
Available on crate feature mtls only.
Expand description

Optional parser, will return None on Err::Error.

To chain an error up, see cut.

use nom::combinator::opt;
use nom::character::complete::alpha1;

fn parser(i: &str) -> IResult<&str, Option<&str>> {
  opt(alpha1)(i)
}

assert_eq!(parser("abcd;"), Ok((";", Some("abcd"))));
assert_eq!(parser("123;"), Ok(("123;", None)));