nom
nom copied to clipboard
many0 returning error when no more data present
Prerequisites
Here are a few things you should provide to help me understand the issue:
- Rust version : rustc 1.59.0
- nom version : 7.1
Test case
The test case should return a vec of tuples. However, instead, the returned data is:
Err(Incomplete(Size(2)))
Example test case:
use nom::number::complete::be_u16;
use nom::bytes::streaming::take;
use nom::multi::{many0, length_data};
use nom::combinator::map;
use nom::sequence::tuple;
let input = &[
0u8, 1u8, 0u8, 2u8, 127u8, 127u8, 0u8, 22u8, 0u8, 3u8, 255u8, 0u8, 255u8, 0u8, 19u8, 0u8, 3u8, 111u8, 222u8, 111u8
];
many0(map(
tuple((
take(2usize),
length_data(be_u16),
)),
|(fmt, val): (&[u8], &[u8])| {
(fmt, val)
},
))(input);
When printing out each iteration within the map
, I can see the bytes are correctly consumed in the right quantities.
This is intended behaviour. By using bytes::streaming::take
, you're opting in to it - there is no way to know if this is actually the end of the data or if there might be more, so take()
returns Incomplete
. You can use bytes::complete::take
if you just want to read everything until the end of input.
That makes absolute logical sense, and I put this down to me posting the issue at 11pm last night 😜
Thank you for the prompt response.