Function nom::combinator::flat_map [−][src]
pub fn flat_map<I, O1, O2, E: ParseError<I>, F, G, H>(
first: F,
second: G
) -> impl FnMut(I) -> IResult<I, O2, E> where
F: Parser<I, O1, E>,
G: Fn(O1) -> H,
H: Parser<I, O2, E>,
Creates a new parser from the output of the first parser, then apply that parser over the rest of the input.
use nom::bytes::complete::take; use nom::number::complete::u8; use nom::combinator::flat_map; let mut parse = flat_map(u8, take); assert_eq!(parse(&[2, 0, 1, 2][..]), Ok((&[2][..], &[0, 1][..]))); assert_eq!(parse(&[4, 0, 1, 2][..]), Err(Err::Error((&[0, 1, 2][..], ErrorKind::Eof))));