rocket::mtls::x509::der_parser::asn1_rs::nom::sequence

Function separated_pair

Source
pub fn separated_pair<I, O1, O2, O3, E, F, G, H>(
    first: F,
    sep: G,
    second: H,
) -> impl FnMut(I)
where E: ParseError<I>, F: Parser<I, O1, E>, G: Parser<I, O2, E>, H: Parser<I, O3, E>,
Available on crate feature mtls only.
Expand description

Gets an object from the first parser, then matches an object from the sep_parser and discards it, then gets another object from the second parser.

ยงArguments

  • first The first parser to apply.
  • sep The separator parser to apply.
  • second The second parser to apply.
use nom::sequence::separated_pair;
use nom::bytes::complete::tag;

let mut parser = separated_pair(tag("abc"), tag("|"), tag("efg"));

assert_eq!(parser("abc|efg"), Ok(("", ("abc", "efg"))));
assert_eq!(parser("abc|efghij"), Ok(("hij", ("abc", "efg"))));
assert_eq!(parser(""), Err(Err::Error(("", ErrorKind::Tag))));
assert_eq!(parser("123"), Err(Err::Error(("123", ErrorKind::Tag))));