Function nom::combinator::into
source · pub fn into<I, O1, O2, E1, E2, F>(
parser: F,
) -> impl FnMut(I) -> IResult<I, O2, E2>
Expand description
automatically converts the child parser’s result to another type
it will be able to convert the output value and the error value
as long as the Into
implementations are available
use nom::combinator::into;
use nom::character::complete::alpha1;
fn parser1(i: &str) -> IResult<&str, &str> {
alpha1(i)
}
let mut parser2 = into(parser1);
// the parser converts the &str output of the child parser into a Vec<u8>
let bytes: IResult<&str, Vec<u8>> = parser2("abcd");
assert_eq!(bytes, Ok(("", vec![97, 98, 99, 100])));