rocket::mtls::x509::der_parser::asn1_rs::nom::multi

Function length_data

Source
pub fn length_data<I, N, E, F>(f: F) -> impl FnMut(I)
where I: InputLength + InputTake, N: ToUsize, F: Parser<I, N, E>, E: ParseError<I>,
Available on crate feature mtls only.
Expand description

Gets a number from the parser and returns a subslice of the input of that size. If the parser returns Incomplete, length_data will return an error.

ยงArguments

  • f The parser to apply.
use nom::number::complete::be_u16;
use nom::multi::length_data;
use nom::bytes::complete::tag;

fn parser(s: &[u8]) -> IResult<&[u8], &[u8]> {
  length_data(be_u16)(s)
}

assert_eq!(parser(b"\x00\x03abcefg"), Ok((&b"efg"[..], &b"abc"[..])));
assert_eq!(parser(b"\x00\x03a"), Err(Err::Incomplete(Needed::new(2))));