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

source ·
pub fn into<I, O1, O2, E1, E2, F>(parser: F) -> impl FnMut(I)
where O1: Into<O2>, E1: Into<E2> + ParseError<I>, E2: ParseError<I>, F: Parser<I, O1, E1>,
Available on crate feature mtls only.
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])));