Macro nom::length_value [−][src]
length_value!(I -> IResult<I, nb>, I -> IResult<I,O>) => I -> IResult<I, O>
Gets a number from the first parser, takes a subslice of the input of that size,
then applies the second parser on that subslice. If the second parser returns
Incomplete
, length_value
will return an error
use nom::number::complete::be_u8; use nom::character::complete::alpha0; use nom::bytes::complete::tag; named!(parser, length_value!(be_u8, alpha0)); assert_eq!(parser(&b"\x06abcabcabc"[..]), Ok((&b"abc"[..], &b"abcabc"[..]))); assert_eq!(parser(&b"\x06abc"[..]), Err(Err::Incomplete(Needed::Size(6))));