Macro nom::parse_to[][src]

macro_rules! parse_to {
    ($i:expr, $t:ty ) => { ... };
}

parse_to!(O) => I -> IResult<I, O> uses the parse method from std::str::FromStr to convert the current input to the specified type

this will completely consume the input

use nom::character::complete::digit1;

named!(parser<&str, u8>, parse_to!(u8));

assert_eq!(parser("123"), Ok(("", 123)));

assert_eq!(parser("abc"), Err(Err::Error(("abc", ErrorKind::ParseTo))));

// this will fail if the mapped function fails (a `u8` is too small to hold `123456`)
assert_eq!(parser("123456"), Err(Err::Error(("123456", ErrorKind::ParseTo))));