Macro nom::map_res [−][src]
map_res!(I -> IResult<I, O>, O -> Result<P>) => I -> IResult<I, P>
maps a function returning a Result on the output of a parser
use nom::character::complete::digit1; named!(parse<&str, u8>, map_res!(digit1, |s: &str| s.parse::<u8>())); // the parser will convert the result of digit1 to a number assert_eq!(parse("123"), Ok(("", 123))); // this will fail if digit1 fails assert_eq!(parse("abc"), Err(Err::Error(error_position!("abc", ErrorKind::Digit)))); // this will fail if the mapped function fails (a `u8` is too small to hold `123456`) assert_eq!(parse("123456"), Err(Err::Error(error_position!("123456", ErrorKind::MapRes))));