[][src]Function nom::combinator::flat_map

pub fn flat_map<I, O1, O2, E: ParseError<I>, F, G, H>(
    first: F,
    second: G
) -> impl Fn(I) -> IResult<I, O2, E> where
    F: Fn(I) -> IResult<I, O1, E>,
    G: Fn(O1) -> H,
    H: Fn(I) -> IResult<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::be_u8;
use nom::combinator::flat_map;

let parse = flat_map(be_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))));