[][src]Function nom::combinator::map

pub fn map<I, O1, O2, E: ParseError<I>, F, G>(
    first: F,
    second: G
) -> impl Fn(I) -> IResult<I, O2, E> where
    F: Fn(I) -> IResult<I, O1, E>,
    G: Fn(O1) -> O2, 

maps a function on the result of a parser

use nom::character::complete::digit1;
use nom::combinator::map;

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

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

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