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

source ยท
pub fn map<I, O1, O2, E, F, G>(parser: F, f: G) -> impl FnMut(I)
where F: Parser<I, O1, E>, G: FnMut(O1) -> O2,
Available on crate feature mtls only.
Expand description

Maps a function on the result of a parser.

use nom::{Err,error::ErrorKind, IResult,Parser};
use nom::character::complete::digit1;
use nom::combinator::map;

let mut parser = map(digit1, |s: &str| s.len());

// the parser will count how many characters were returned by digit1
assert_eq!(parser.parse("123456"), Ok(("", 6)));

// this will fail if digit1 fails
assert_eq!(parser.parse("abc"), Err(Err::Error(("abc", ErrorKind::Digit))));