diff options
Diffstat (limited to 'vendor/winnow/src/binary')
-rw-r--r-- | vendor/winnow/src/binary/bits/mod.rs | 189 | ||||
-rw-r--r-- | vendor/winnow/src/binary/bits/tests.rs | 55 | ||||
-rw-r--r-- | vendor/winnow/src/binary/mod.rs | 734 | ||||
-rw-r--r-- | vendor/winnow/src/binary/tests.rs | 460 |
4 files changed, 755 insertions, 683 deletions
diff --git a/vendor/winnow/src/binary/bits/mod.rs b/vendor/winnow/src/binary/bits/mod.rs index 5400e3308..334c6bf00 100644 --- a/vendor/winnow/src/binary/bits/mod.rs +++ b/vendor/winnow/src/binary/bits/mod.rs @@ -4,11 +4,11 @@ #[cfg(test)] mod tests; -use crate::error::{ErrMode, ErrorConvert, ErrorKind, Needed, ParseError}; +use crate::error::{ErrMode, ErrorConvert, ErrorKind, Needed, ParserError}; use crate::lib::std::ops::{AddAssign, Div, Shl, Shr}; use crate::stream::{AsBytes, Stream, StreamIsPartial, ToUsize}; use crate::trace::trace; -use crate::{IResult, Parser}; +use crate::{unpeek, IResult, PResult, Parser}; /// Converts a byte-level input to a bit-level input /// @@ -19,7 +19,7 @@ use crate::{IResult, Parser}; /// use winnow::prelude::*; /// use winnow::Bytes; /// use winnow::binary::bits::{bits, take}; -/// use winnow::error::Error; +/// use winnow::error::InputError; /// /// type Stream<'i> = &'i Bytes; /// @@ -28,7 +28,7 @@ use crate::{IResult, Parser}; /// } /// /// fn parse(input: Stream<'_>) -> IResult<Stream<'_>, (u8, u8)> { -/// bits::<_, _, Error<(_, usize)>, _, _>((take(4usize), take(8usize))).parse_next(input) +/// bits::<_, _, InputError<(_, usize)>, _, _>((take(4usize), take(8usize))).parse_peek(input) /// } /// /// let input = stream(&[0x12, 0x34, 0xff, 0xff]); @@ -45,25 +45,28 @@ use crate::{IResult, Parser}; /// ``` pub fn bits<I, O, E1, E2, P>(mut parser: P) -> impl Parser<I, O, E2> where - E1: ParseError<(I, usize)> + ErrorConvert<E2>, - E2: ParseError<I>, - I: Stream, + E1: ParserError<(I, usize)> + ErrorConvert<E2>, + E2: ParserError<I>, + I: Stream + Clone, P: Parser<(I, usize), O, E1>, { - trace("bits", move |input: I| { - match parser.parse_next((input, 0)) { - Ok(((rest, offset), result)) => { - // If the next byte has been partially read, it will be sliced away as well. - // The parser functions might already slice away all fully read bytes. - // That's why `offset / 8` isn't necessarily needed at all times. - let remaining_bytes_index = offset / 8 + if offset % 8 == 0 { 0 } else { 1 }; - let (input, _) = rest.next_slice(remaining_bytes_index); - Ok((input, result)) + trace( + "bits", + unpeek(move |input: I| { + match parser.parse_peek((input, 0)) { + Ok(((rest, offset), result)) => { + // If the next byte has been partially read, it will be sliced away as well. + // The parser functions might already slice away all fully read bytes. + // That's why `offset / 8` isn't necessarily needed at all times. + let remaining_bytes_index = offset / 8 + if offset % 8 == 0 { 0 } else { 1 }; + let (input, _) = rest.peek_slice(remaining_bytes_index); + Ok((input, result)) + } + Err(ErrMode::Incomplete(n)) => Err(ErrMode::Incomplete(n.map(|u| u.get() / 8 + 1))), + Err(e) => Err(e.convert()), } - Err(ErrMode::Incomplete(n)) => Err(ErrMode::Incomplete(n.map(|u| u.get() / 8 + 1))), - Err(e) => Err(e.convert()), - } - }) + }), + ) } /// Convert a [`bits`] stream back into a byte stream @@ -76,7 +79,7 @@ where /// use winnow::Bytes; /// use winnow::binary::bits::{bits, bytes, take}; /// use winnow::combinator::rest; -/// use winnow::error::Error; +/// use winnow::error::InputError; /// /// type Stream<'i> = &'i Bytes; /// @@ -85,11 +88,11 @@ where /// } /// /// fn parse(input: Stream<'_>) -> IResult<Stream<'_>, (u8, u8, &[u8])> { -/// bits::<_, _, Error<(_, usize)>, _, _>(( +/// bits::<_, _, InputError<(_, usize)>, _, _>(( /// take(4usize), /// take(8usize), -/// bytes::<_, _, Error<_>, _, _>(rest) -/// )).parse_next(input) +/// bytes::<_, _, InputError<_>, _, _>(rest) +/// )).parse_peek(input) /// } /// /// let input = stream(&[0x12, 0x34, 0xff, 0xff]); @@ -98,31 +101,36 @@ where /// ``` pub fn bytes<I, O, E1, E2, P>(mut parser: P) -> impl Parser<(I, usize), O, E2> where - E1: ParseError<I> + ErrorConvert<E2>, - E2: ParseError<(I, usize)>, - I: Stream<Token = u8>, + E1: ParserError<I> + ErrorConvert<E2>, + E2: ParserError<(I, usize)>, + I: Stream<Token = u8> + Clone, P: Parser<I, O, E1>, { - trace("bytes", move |(input, offset): (I, usize)| { - let (inner, _) = if offset % 8 != 0 { - input.next_slice(1 + offset / 8) - } else { - input.next_slice(offset / 8) - }; - let i = (input, offset); - match parser.parse_next(inner) { - Ok((rest, res)) => Ok(((rest, 0), res)), - Err(ErrMode::Incomplete(Needed::Unknown)) => Err(ErrMode::Incomplete(Needed::Unknown)), - Err(ErrMode::Incomplete(Needed::Size(sz))) => Err(match sz.get().checked_mul(8) { - Some(v) => ErrMode::Incomplete(Needed::new(v)), - None => ErrMode::Cut(E2::assert( - i, - "overflow in turning needed bytes into needed bits", - )), - }), - Err(e) => Err(e.convert()), - } - }) + trace( + "bytes", + unpeek(move |(input, offset): (I, usize)| { + let (inner, _) = if offset % 8 != 0 { + input.peek_slice(1 + offset / 8) + } else { + input.peek_slice(offset / 8) + }; + let i = (input, offset); + match parser.parse_peek(inner) { + Ok((rest, res)) => Ok(((rest, 0), res)), + Err(ErrMode::Incomplete(Needed::Unknown)) => { + Err(ErrMode::Incomplete(Needed::Unknown)) + } + Err(ErrMode::Incomplete(Needed::Size(sz))) => Err(match sz.get().checked_mul(8) { + Some(v) => ErrMode::Incomplete(Needed::new(v)), + None => ErrMode::Cut(E2::assert( + &i, + "overflow in turning needed bytes into needed bits", + )), + }), + Err(e) => Err(e.convert()), + } + }), + ) } /// Parse taking `count` bits @@ -131,7 +139,7 @@ where /// ```rust /// # use winnow::prelude::*; /// # use winnow::Bytes; -/// # use winnow::error::{Error, ErrorKind}; +/// # use winnow::error::{InputError, ErrorKind}; /// use winnow::binary::bits::take; /// /// type Stream<'i> = &'i Bytes; @@ -141,7 +149,7 @@ where /// } /// /// fn parser(input: (Stream<'_>, usize), count: usize)-> IResult<(Stream<'_>, usize), u8> { -/// take(count).parse_next(input) +/// take(count).parse_peek(input) /// } /// /// // Consumes 0 bits, returns 0 @@ -154,32 +162,35 @@ where /// assert_eq!(parser((stream(&[0b00010010]), 4), 4), Ok(((stream(&[]), 0), 0b00000010))); /// /// // Tries to consume 12 bits but only 8 are available -/// assert_eq!(parser((stream(&[0b00010010]), 0), 12), Err(winnow::error::ErrMode::Backtrack(Error{input: (stream(&[0b00010010]), 0), kind: ErrorKind::Eof }))); +/// assert_eq!(parser((stream(&[0b00010010]), 0), 12), Err(winnow::error::ErrMode::Backtrack(InputError::new((stream(&[0b00010010]), 0), ErrorKind::Eof)))); /// ``` #[inline(always)] -pub fn take<I, O, C, E: ParseError<(I, usize)>>(count: C) -> impl Parser<(I, usize), O, E> +pub fn take<I, O, C, E: ParserError<(I, usize)>>(count: C) -> impl Parser<(I, usize), O, E> where - I: Stream<Token = u8> + AsBytes + StreamIsPartial, + I: Stream<Token = u8> + AsBytes + StreamIsPartial + Clone, C: ToUsize, O: From<u8> + AddAssign + Shl<usize, Output = O> + Shr<usize, Output = O>, { let count = count.to_usize(); - trace("take", move |input: (I, usize)| { - if <I as StreamIsPartial>::is_partial_supported() { - take_::<_, _, _, true>(input, count) - } else { - take_::<_, _, _, false>(input, count) - } - }) + trace( + "take", + unpeek(move |input: (I, usize)| { + if <I as StreamIsPartial>::is_partial_supported() { + take_::<_, _, _, true>(input, count) + } else { + take_::<_, _, _, false>(input, count) + } + }), + ) } -fn take_<I, O, E: ParseError<(I, usize)>, const PARTIAL: bool>( +fn take_<I, O, E: ParserError<(I, usize)>, const PARTIAL: bool>( (input, bit_offset): (I, usize), count: usize, ) -> IResult<(I, usize), O, E> where I: StreamIsPartial, - I: Stream<Token = u8> + AsBytes, + I: Stream<Token = u8> + AsBytes + Clone, O: From<u8> + AddAssign + Shl<usize, Output = O> + Shr<usize, Output = O>, { if count == 0 { @@ -191,7 +202,7 @@ where Err(ErrMode::Incomplete(Needed::new(count))) } else { Err(ErrMode::from_error_kind( - (input, bit_offset), + &(input, bit_offset), ErrorKind::Eof, )) } @@ -221,7 +232,7 @@ where offset = 0; } } - let (input, _) = input.next_slice(cnt); + let (input, _) = input.peek_slice(cnt); Ok(((input, end_offset), acc)) } } @@ -234,7 +245,7 @@ where /// ```rust /// # use winnow::prelude::*; /// # use winnow::Bytes; -/// # use winnow::error::{Error, ErrorKind}; +/// # use winnow::error::{InputError, ErrorKind}; /// use winnow::binary::bits::tag; /// /// type Stream<'i> = &'i Bytes; @@ -247,7 +258,7 @@ where /// /// Return Ok and the matching section of `input` if there's a match. /// /// Return Err if there's no match. /// fn parser(pattern: u8, count: u8, input: (Stream<'_>, usize)) -> IResult<(Stream<'_>, usize), u8> { -/// tag(pattern, count).parse_next(input) +/// tag(pattern, count).parse_peek(input) /// } /// /// // The lowest 4 bits of 0b00001111 match the lowest 4 bits of 0b11111111. @@ -265,42 +276,46 @@ where /// // The lowest 2 bits of 0b11111111 and 0b00000001 are different. /// assert_eq!( /// parser(0b000000_01, 2, (stream(&[0b111111_11]), 0)), -/// Err(winnow::error::ErrMode::Backtrack(Error { -/// input: (stream(&[0b11111111]), 0), -/// kind: ErrorKind::Tag -/// })) +/// Err(winnow::error::ErrMode::Backtrack(InputError::new( +/// (stream(&[0b11111111]), 0), +/// ErrorKind::Tag +/// ))) /// ); /// /// // The lowest 8 bits of 0b11111111 and 0b11111110 are different. /// assert_eq!( /// parser(0b11111110, 8, (stream(&[0b11111111]), 0)), -/// Err(winnow::error::ErrMode::Backtrack(Error { -/// input: (stream(&[0b11111111]), 0), -/// kind: ErrorKind::Tag -/// })) +/// Err(winnow::error::ErrMode::Backtrack(InputError::new( +/// (stream(&[0b11111111]), 0), +/// ErrorKind::Tag +/// ))) /// ); /// ``` #[inline(always)] #[doc(alias = "literal")] #[doc(alias = "just")] -pub fn tag<I, O, C, E: ParseError<(I, usize)>>( +pub fn tag<I, O, C, E: ParserError<(I, usize)>>( pattern: O, count: C, ) -> impl Parser<(I, usize), O, E> where - I: Stream<Token = u8> + AsBytes + StreamIsPartial, + I: Stream<Token = u8> + AsBytes + StreamIsPartial + Clone, C: ToUsize, O: From<u8> + AddAssign + Shl<usize, Output = O> + Shr<usize, Output = O> + PartialEq, { let count = count.to_usize(); - trace("tag", move |input: (I, usize)| { - let inp = input.clone(); + trace("tag", move |input: &mut (I, usize)| { + let start = input.checkpoint(); - take(count).parse_next(input).and_then(|(i, o)| { + take(count).parse_next(input).and_then(|o| { if pattern == o { - Ok((i, o)) + Ok(o) } else { - Err(ErrMode::Backtrack(E::from_error_kind(inp, ErrorKind::Tag))) + input.reset(start); + Err(ErrMode::Backtrack(E::from_error_kind( + input, + ErrorKind::Tag, + ))) } }) }) @@ -313,7 +328,7 @@ where /// ```rust /// # use winnow::prelude::*; /// # use winnow::Bytes; -/// # use winnow::error::{Error, ErrorKind}; +/// # use winnow::error::{InputError, ErrorKind}; /// use winnow::binary::bits::bool; /// /// type Stream<'i> = &'i Bytes; @@ -323,20 +338,20 @@ where /// } /// /// fn parse(input: (Stream<'_>, usize)) -> IResult<(Stream<'_>, usize), bool> { -/// bool.parse_next(input) +/// bool.parse_peek(input) /// } /// /// assert_eq!(parse((stream(&[0b10000000]), 0)), Ok(((stream(&[0b10000000]), 1), true))); /// assert_eq!(parse((stream(&[0b10000000]), 1)), Ok(((stream(&[0b10000000]), 2), false))); /// ``` #[doc(alias = "any")] -pub fn bool<I, E: ParseError<(I, usize)>>(input: (I, usize)) -> IResult<(I, usize), bool, E> +pub fn bool<I, E: ParserError<(I, usize)>>(input: &mut (I, usize)) -> PResult<bool, E> where - I: Stream<Token = u8> + AsBytes + StreamIsPartial, + I: Stream<Token = u8> + AsBytes + StreamIsPartial + Clone, { - trace("bool", |input: (I, usize)| { - let (res, bit): (_, u32) = take(1usize).parse_next(input)?; - Ok((res, bit != 0)) + trace("bool", |input: &mut (I, usize)| { + let bit: u32 = take(1usize).parse_next(input)?; + Ok(bit != 0) }) .parse_next(input) } diff --git a/vendor/winnow/src/binary/bits/tests.rs b/vendor/winnow/src/binary/bits/tests.rs index 61dba2c31..41207c624 100644 --- a/vendor/winnow/src/binary/bits/tests.rs +++ b/vendor/winnow/src/binary/bits/tests.rs @@ -1,5 +1,5 @@ use super::*; -use crate::error::Error; +use crate::error::InputError; use crate::Partial; #[test] @@ -10,8 +10,8 @@ fn test_complete_byte_consumption_bits() { // Take 3 bit slices with sizes [4, 8, 4]. let result: IResult<&[u8], (u8, u8, u8)> = - bits::<_, _, Error<(&[u8], usize)>, _, _>((take(4usize), take(8usize), take(4usize))) - .parse_next(input); + bits::<_, _, InputError<(&[u8], usize)>, _, _>((take(4usize), take(8usize), take(4usize))) + .parse_peek(input); let output = result.expect("We take 2 bytes and the input is longer than 2 bytes"); @@ -34,7 +34,8 @@ fn test_partial_byte_consumption_bits() { // Take bit slices with sizes [4, 8]. let result: IResult<&[u8], (u8, u8)> = - bits::<_, _, Error<(&[u8], usize)>, _, _>((take(4usize), take(8usize))).parse_next(input); + bits::<_, _, InputError<(&[u8], usize)>, _, _>((take(4usize), take(8usize))) + .parse_peek(input); let output = result.expect("We take 1.5 bytes and the input is longer than 2 bytes"); @@ -54,7 +55,7 @@ fn test_incomplete_bits() { // Take bit slices with sizes [4, 8]. let result: IResult<_, (u8, u8)> = - bits::<_, _, Error<(_, usize)>, _, _>((take(4usize), take(8usize))).parse_next(input); + bits::<_, _, InputError<(_, usize)>, _, _>((take(4usize), take(8usize))).parse_peek(input); assert!(result.is_err()); let error = result.err().unwrap(); @@ -68,7 +69,7 @@ fn test_take_complete_0() { assert_eq!(count, 0usize); let offset = 0usize; - let result: crate::IResult<(&[u8], usize), usize> = take(count).parse_next((input, offset)); + let result: crate::IResult<(&[u8], usize), usize> = take(count).parse_peek((input, offset)); assert_eq!(result, Ok(((input, offset), 0))); } @@ -77,14 +78,14 @@ fn test_take_complete_0() { fn test_take_complete_eof() { let input = &[0b00010010][..]; - let result: crate::IResult<(&[u8], usize), usize> = take(1usize).parse_next((input, 8)); + let result: crate::IResult<(&[u8], usize), usize> = take(1usize).parse_peek((input, 8)); assert_eq!( result, - Err(crate::error::ErrMode::Backtrack(crate::error::Error { - input: (input, 8), - kind: ErrorKind::Eof - })) + Err(crate::error::ErrMode::Backtrack(InputError::new( + (input, 8), + ErrorKind::Eof + ))) ); } @@ -92,7 +93,7 @@ fn test_take_complete_eof() { fn test_take_complete_span_over_multiple_bytes() { let input = &[0b00010010, 0b00110100, 0b11111111, 0b11111111][..]; - let result: crate::IResult<(&[u8], usize), usize> = take(24usize).parse_next((input, 4)); + let result: crate::IResult<(&[u8], usize), usize> = take(24usize).parse_peek((input, 4)); assert_eq!( result, @@ -107,7 +108,7 @@ fn test_take_partial_0() { assert_eq!(count, 0usize); let offset = 0usize; - let result: crate::IResult<(_, usize), usize> = take(count).parse_next((input, offset)); + let result: crate::IResult<(_, usize), usize> = take(count).parse_peek((input, offset)); assert_eq!(result, Ok(((input, offset), 0))); } @@ -120,7 +121,7 @@ fn test_tag_partial_ok() { let value_to_tag = 0b0001; let result: crate::IResult<(_, usize), usize> = - tag(value_to_tag, bits_to_take).parse_next((input, offset)); + tag(value_to_tag, bits_to_take).parse_peek((input, offset)); assert_eq!(result, Ok(((input, bits_to_take), value_to_tag))); } @@ -133,14 +134,14 @@ fn test_tag_partial_err() { let value_to_tag = 0b1111; let result: crate::IResult<(_, usize), usize> = - tag(value_to_tag, bits_to_take).parse_next((input, offset)); + tag(value_to_tag, bits_to_take).parse_peek((input, offset)); assert_eq!( result, - Err(crate::error::ErrMode::Backtrack(crate::error::Error { - input: (input, offset), - kind: ErrorKind::Tag - })) + Err(crate::error::ErrMode::Backtrack(InputError::new( + (input, offset), + ErrorKind::Tag + ))) ); } @@ -148,7 +149,7 @@ fn test_tag_partial_err() { fn test_bool_0_complete() { let input = [0b10000000].as_ref(); - let result: crate::IResult<(&[u8], usize), bool> = bool((input, 0)); + let result: crate::IResult<(&[u8], usize), bool> = bool.parse_peek((input, 0)); assert_eq!(result, Ok(((input, 1), true))); } @@ -157,14 +158,14 @@ fn test_bool_0_complete() { fn test_bool_eof_complete() { let input = [0b10000000].as_ref(); - let result: crate::IResult<(&[u8], usize), bool> = bool((input, 8)); + let result: crate::IResult<(&[u8], usize), bool> = bool.parse_peek((input, 8)); assert_eq!( result, - Err(crate::error::ErrMode::Backtrack(crate::error::Error { - input: (input, 8), - kind: ErrorKind::Eof - })) + Err(crate::error::ErrMode::Backtrack(InputError::new( + (input, 8), + ErrorKind::Eof + ))) ); } @@ -172,7 +173,7 @@ fn test_bool_eof_complete() { fn test_bool_0_partial() { let input = Partial::new([0b10000000].as_ref()); - let result: crate::IResult<(Partial<&[u8]>, usize), bool> = bool((input, 0)); + let result: crate::IResult<(Partial<&[u8]>, usize), bool> = bool.parse_peek((input, 0)); assert_eq!(result, Ok(((input, 1), true))); } @@ -181,7 +182,7 @@ fn test_bool_0_partial() { fn test_bool_eof_partial() { let input = Partial::new([0b10000000].as_ref()); - let result: crate::IResult<(Partial<&[u8]>, usize), bool> = bool.parse_next((input, 8)); + let result: crate::IResult<(Partial<&[u8]>, usize), bool> = bool.parse_peek((input, 8)); assert_eq!( result, diff --git a/vendor/winnow/src/binary/mod.rs b/vendor/winnow/src/binary/mod.rs index 80435e359..8b2ee74ee 100644 --- a/vendor/winnow/src/binary/mod.rs +++ b/vendor/winnow/src/binary/mod.rs @@ -11,14 +11,14 @@ use crate::combinator::repeat; use crate::error::ErrMode; use crate::error::ErrorKind; use crate::error::Needed; -use crate::error::ParseError; +use crate::error::ParserError; use crate::lib::std::ops::{Add, Shl}; use crate::stream::Accumulate; use crate::stream::{AsBytes, Stream, StreamIsPartial}; use crate::stream::{ToUsize, UpdateSlice}; use crate::token::take; use crate::trace::trace; -use crate::IResult; +use crate::PResult; use crate::Parser; /// Configurable endianness @@ -41,34 +41,34 @@ pub enum Endianness { /// # Example /// /// ```rust -/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed}; +/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed}; /// # use winnow::prelude::*; /// # use winnow::error::Needed::Size; /// use winnow::binary::be_u8; /// /// fn parser(s: &[u8]) -> IResult<&[u8], u8> { -/// be_u8.parse_next(s) +/// be_u8.parse_peek(s) /// } /// /// assert_eq!(parser(&b"\x00\x03abcefg"[..]), Ok((&b"\x03abcefg"[..], 0x00))); -/// assert_eq!(parser(&b""[..]), Err(ErrMode::Backtrack(Error::new(&[][..], ErrorKind::Token)))); +/// assert_eq!(parser(&b""[..]), Err(ErrMode::Backtrack(InputError::new(&[][..], ErrorKind::Token)))); /// ``` /// /// ```rust -/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed}; +/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed}; /// # use winnow::prelude::*; /// # use winnow::Partial; /// use winnow::binary::be_u8; /// /// fn parser(s: Partial<&[u8]>) -> IResult<Partial<&[u8]>, u8> { -/// be_u8.parse_next(s) +/// be_u8.parse_peek(s) /// } /// /// assert_eq!(parser(Partial::new(&b"\x00\x01abcd"[..])), Ok((Partial::new(&b"\x01abcd"[..]), 0x00))); /// assert_eq!(parser(Partial::new(&b""[..])), Err(ErrMode::Incomplete(Needed::new(1)))); /// ``` #[inline(always)] -pub fn be_u8<I, E: ParseError<I>>(input: I) -> IResult<I, u8, E> +pub fn be_u8<I, E: ParserError<I>>(input: &mut I) -> PResult<u8, E> where I: StreamIsPartial, I: Stream<Token = u8>, @@ -85,40 +85,40 @@ where /// # Example /// /// ```rust -/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed}; +/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed}; /// # use winnow::prelude::*; /// # use winnow::error::Needed::Size; /// use winnow::binary::be_u16; /// /// fn parser(s: &[u8]) -> IResult<&[u8], u16> { -/// be_u16.parse_next(s) +/// be_u16.parse_peek(s) /// } /// /// assert_eq!(parser(&b"\x00\x03abcefg"[..]), Ok((&b"abcefg"[..], 0x0003))); -/// assert_eq!(parser(&b"\x01"[..]), Err(ErrMode::Backtrack(Error::new(&[0x01][..], ErrorKind::Slice)))); +/// assert_eq!(parser(&b"\x01"[..]), Err(ErrMode::Backtrack(InputError::new(&[0x01][..], ErrorKind::Slice)))); /// ``` /// /// ```rust -/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed}; +/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed}; /// # use winnow::prelude::*; /// # use winnow::Partial; /// use winnow::binary::be_u16; /// /// fn parser(s: Partial<&[u8]>) -> IResult<Partial<&[u8]>, u16> { -/// be_u16.parse_next(s) +/// be_u16.parse_peek(s) /// } /// /// assert_eq!(parser(Partial::new(&b"\x00\x01abcd"[..])), Ok((Partial::new(&b"abcd"[..]), 0x0001))); /// assert_eq!(parser(Partial::new(&b"\x01"[..])), Err(ErrMode::Incomplete(Needed::new(1)))); /// ``` #[inline(always)] -pub fn be_u16<I, E: ParseError<I>>(input: I) -> IResult<I, u16, E> +pub fn be_u16<I, E: ParserError<I>>(input: &mut I) -> PResult<u16, E> where I: StreamIsPartial, I: Stream<Token = u8>, <I as Stream>::Slice: AsBytes, { - trace("be_u16", move |input: I| be_uint(input, 2)).parse_next(input) + trace("be_u16", move |input: &mut I| be_uint(input, 2)).parse_next(input) } /// Recognizes a big endian unsigned 3 byte integer. @@ -130,40 +130,40 @@ where /// # Example /// /// ```rust -/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed}; +/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed}; /// # use winnow::prelude::*; /// # use winnow::error::Needed::Size; /// use winnow::binary::be_u24; /// /// fn parser(s: &[u8]) -> IResult<&[u8], u32> { -/// be_u24.parse_next(s) +/// be_u24.parse_peek(s) /// } /// /// assert_eq!(parser(&b"\x00\x03\x05abcefg"[..]), Ok((&b"abcefg"[..], 0x000305))); -/// assert_eq!(parser(&b"\x01"[..]), Err(ErrMode::Backtrack(Error::new(&[0x01][..], ErrorKind::Slice)))); +/// assert_eq!(parser(&b"\x01"[..]), Err(ErrMode::Backtrack(InputError::new(&[0x01][..], ErrorKind::Slice)))); /// ``` /// /// ```rust -/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed}; +/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed}; /// # use winnow::prelude::*; /// # use winnow::Partial; /// use winnow::binary::be_u24; /// /// fn parser(s: Partial<&[u8]>) -> IResult<Partial<&[u8]>, u32> { -/// be_u24.parse_next(s) +/// be_u24.parse_peek(s) /// } /// /// assert_eq!(parser(Partial::new(&b"\x00\x01\x02abcd"[..])), Ok((Partial::new(&b"abcd"[..]), 0x000102))); /// assert_eq!(parser(Partial::new(&b"\x01"[..])), Err(ErrMode::Incomplete(Needed::new(2)))); /// ``` #[inline(always)] -pub fn be_u24<I, E: ParseError<I>>(input: I) -> IResult<I, u32, E> +pub fn be_u24<I, E: ParserError<I>>(input: &mut I) -> PResult<u32, E> where I: StreamIsPartial, I: Stream<Token = u8>, <I as Stream>::Slice: AsBytes, { - trace("be_u23", move |input: I| be_uint(input, 3)).parse_next(input) + trace("be_u23", move |input: &mut I| be_uint(input, 3)).parse_next(input) } /// Recognizes a big endian unsigned 4 bytes integer. @@ -175,40 +175,40 @@ where /// # Example /// /// ```rust -/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed}; +/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed}; /// # use winnow::prelude::*; /// # use winnow::error::Needed::Size; /// use winnow::binary::be_u32; /// /// fn parser(s: &[u8]) -> IResult<&[u8], u32> { -/// be_u32.parse_next(s) +/// be_u32.parse_peek(s) /// } /// /// assert_eq!(parser(&b"\x00\x03\x05\x07abcefg"[..]), Ok((&b"abcefg"[..], 0x00030507))); -/// assert_eq!(parser(&b"\x01"[..]), Err(ErrMode::Backtrack(Error::new(&[0x01][..], ErrorKind::Slice)))); +/// assert_eq!(parser(&b"\x01"[..]), Err(ErrMode::Backtrack(InputError::new(&[0x01][..], ErrorKind::Slice)))); /// ``` /// /// ```rust -/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed}; +/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed}; /// # use winnow::prelude::*; /// # use winnow::Partial; /// use winnow::binary::be_u32; /// /// fn parser(s: Partial<&[u8]>) -> IResult<Partial<&[u8]>, u32> { -/// be_u32.parse_next(s) +/// be_u32.parse_peek(s) /// } /// /// assert_eq!(parser(Partial::new(&b"\x00\x01\x02\x03abcd"[..])), Ok((Partial::new(&b"abcd"[..]), 0x00010203))); /// assert_eq!(parser(Partial::new(&b"\x01"[..])), Err(ErrMode::Incomplete(Needed::new(3)))); /// ``` #[inline(always)] -pub fn be_u32<I, E: ParseError<I>>(input: I) -> IResult<I, u32, E> +pub fn be_u32<I, E: ParserError<I>>(input: &mut I) -> PResult<u32, E> where I: StreamIsPartial, I: Stream<Token = u8>, <I as Stream>::Slice: AsBytes, { - trace("be_u32", move |input: I| be_uint(input, 4)).parse_next(input) + trace("be_u32", move |input: &mut I| be_uint(input, 4)).parse_next(input) } /// Recognizes a big endian unsigned 8 bytes integer. @@ -220,40 +220,40 @@ where /// # Example /// /// ```rust -/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed}; +/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed}; /// # use winnow::prelude::*; /// # use winnow::error::Needed::Size; /// use winnow::binary::be_u64; /// /// fn parser(s: &[u8]) -> IResult<&[u8], u64> { -/// be_u64.parse_next(s) +/// be_u64.parse_peek(s) /// } /// /// assert_eq!(parser(&b"\x00\x01\x02\x03\x04\x05\x06\x07abcefg"[..]), Ok((&b"abcefg"[..], 0x0001020304050607))); -/// assert_eq!(parser(&b"\x01"[..]), Err(ErrMode::Backtrack(Error::new(&[0x01][..], ErrorKind::Slice)))); +/// assert_eq!(parser(&b"\x01"[..]), Err(ErrMode::Backtrack(InputError::new(&[0x01][..], ErrorKind::Slice)))); /// ``` /// /// ```rust -/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed}; +/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed}; /// # use winnow::prelude::*; /// # use winnow::Partial; /// use winnow::binary::be_u64; /// /// fn parser(s: Partial<&[u8]>) -> IResult<Partial<&[u8]>, u64> { -/// be_u64.parse_next(s) +/// be_u64.parse_peek(s) /// } /// /// assert_eq!(parser(Partial::new(&b"\x00\x01\x02\x03\x04\x05\x06\x07abcd"[..])), Ok((Partial::new(&b"abcd"[..]), 0x0001020304050607))); /// assert_eq!(parser(Partial::new(&b"\x01"[..])), Err(ErrMode::Incomplete(Needed::new(7)))); /// ``` #[inline(always)] -pub fn be_u64<I, E: ParseError<I>>(input: I) -> IResult<I, u64, E> +pub fn be_u64<I, E: ParserError<I>>(input: &mut I) -> PResult<u64, E> where I: StreamIsPartial, I: Stream<Token = u8>, <I as Stream>::Slice: AsBytes, { - trace("be_u64", move |input: I| be_uint(input, 8)).parse_next(input) + trace("be_u64", move |input: &mut I| be_uint(input, 8)).parse_next(input) } /// Recognizes a big endian unsigned 16 bytes integer. @@ -265,44 +265,44 @@ where /// # Example /// /// ```rust -/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed}; +/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed}; /// # use winnow::prelude::*; /// # use winnow::error::Needed::Size; /// use winnow::binary::be_u128; /// /// fn parser(s: &[u8]) -> IResult<&[u8], u128> { -/// be_u128.parse_next(s) +/// be_u128.parse_peek(s) /// } /// /// assert_eq!(parser(&b"\x00\x01\x02\x03\x04\x05\x06\x07\x00\x01\x02\x03\x04\x05\x06\x07abcefg"[..]), Ok((&b"abcefg"[..], 0x00010203040506070001020304050607))); -/// assert_eq!(parser(&b"\x01"[..]), Err(ErrMode::Backtrack(Error::new(&[0x01][..], ErrorKind::Slice)))); +/// assert_eq!(parser(&b"\x01"[..]), Err(ErrMode::Backtrack(InputError::new(&[0x01][..], ErrorKind::Slice)))); /// ``` /// /// ```rust -/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed}; +/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed}; /// # use winnow::prelude::*; /// # use winnow::Partial; /// use winnow::binary::be_u128; /// /// fn parser(s: Partial<&[u8]>) -> IResult<Partial<&[u8]>, u128> { -/// be_u128.parse_next(s) +/// be_u128.parse_peek(s) /// } /// /// assert_eq!(parser(Partial::new(&b"\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x10\x11\x12\x13\x14\x15abcd"[..])), Ok((Partial::new(&b"abcd"[..]), 0x00010203040506070809101112131415))); /// assert_eq!(parser(Partial::new(&b"\x01"[..])), Err(ErrMode::Incomplete(Needed::new(15)))); /// ``` #[inline(always)] -pub fn be_u128<I, E: ParseError<I>>(input: I) -> IResult<I, u128, E> +pub fn be_u128<I, E: ParserError<I>>(input: &mut I) -> PResult<u128, E> where I: StreamIsPartial, I: Stream<Token = u8>, <I as Stream>::Slice: AsBytes, { - trace("be_u128", move |input: I| be_uint(input, 16)).parse_next(input) + trace("be_u128", move |input: &mut I| be_uint(input, 16)).parse_next(input) } #[inline] -fn be_uint<I, Uint, E: ParseError<I>>(input: I, bound: usize) -> IResult<I, Uint, E> +fn be_uint<I, Uint, E: ParserError<I>>(input: &mut I, bound: usize) -> PResult<Uint, E> where I: StreamIsPartial, I: Stream<Token = u8>, @@ -337,34 +337,34 @@ where /// # Example /// /// ```rust -/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed}; +/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed}; /// # use winnow::prelude::*; /// # use winnow::error::Needed::Size; /// use winnow::binary::be_i8; /// /// fn parser(s: &[u8]) -> IResult<&[u8], i8> { -/// be_i8.parse_next(s) +/// be_i8.parse_peek(s) /// } /// /// assert_eq!(parser(&b"\x00\x03abcefg"[..]), Ok((&b"\x03abcefg"[..], 0x00))); -/// assert_eq!(parser(&b""[..]), Err(ErrMode::Backtrack(Error::new(&[][..], ErrorKind::Token)))); +/// assert_eq!(parser(&b""[..]), Err(ErrMode::Backtrack(InputError::new(&[][..], ErrorKind::Token)))); /// ``` /// /// ```rust -/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed}; +/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed}; /// # use winnow::prelude::*; /// # use winnow::Partial; /// use winnow::binary::be_i8; /// /// fn parser(s: Partial<&[u8]>) -> IResult<Partial<&[u8]>, i8> { -/// be_i8.parse_next(s) +/// be_i8.parse_peek(s) /// } /// /// assert_eq!(parser(Partial::new(&b"\x00\x01abcd"[..])), Ok((Partial::new(&b"\x01abcd"[..]), 0x00))); /// assert_eq!(parser(Partial::new(&b""[..])), Err(ErrMode::Incomplete(Needed::new(1)))); /// ``` #[inline(always)] -pub fn be_i8<I, E: ParseError<I>>(input: I) -> IResult<I, i8, E> +pub fn be_i8<I, E: ParserError<I>>(input: &mut I) -> PResult<i8, E> where I: StreamIsPartial, I: Stream<Token = u8>, @@ -381,41 +381,41 @@ where /// # Example /// /// ```rust -/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed}; +/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed}; /// # use winnow::prelude::*; /// # use winnow::error::Needed::Size; /// use winnow::binary::be_i16; /// /// fn parser(s: &[u8]) -> IResult<&[u8], i16> { -/// be_i16.parse_next(s) +/// be_i16.parse_peek(s) /// } /// /// assert_eq!(parser(&b"\x00\x03abcefg"[..]), Ok((&b"abcefg"[..], 0x0003))); -/// assert_eq!(parser(&b"\x01"[..]), Err(ErrMode::Backtrack(Error::new(&[0x01][..], ErrorKind::Slice)))); +/// assert_eq!(parser(&b"\x01"[..]), Err(ErrMode::Backtrack(InputError::new(&[0x01][..], ErrorKind::Slice)))); /// ``` /// /// ```rust -/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed}; +/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed}; /// # use winnow::prelude::*; /// # use winnow::Partial; /// use winnow::binary::be_i16; /// /// fn parser(s: Partial<&[u8]>) -> IResult<Partial<&[u8]>, i16> { -/// be_i16.parse_next(s) +/// be_i16.parse_peek(s) /// } /// /// assert_eq!(parser(Partial::new(&b"\x00\x01abcd"[..])), Ok((Partial::new(&b"abcd"[..]), 0x0001))); /// assert_eq!(parser(Partial::new(&b""[..])), Err(ErrMode::Incomplete(Needed::new(2)))); /// ``` #[inline(always)] -pub fn be_i16<I, E: ParseError<I>>(input: I) -> IResult<I, i16, E> +pub fn be_i16<I, E: ParserError<I>>(input: &mut I) -> PResult<i16, E> where I: StreamIsPartial, I: Stream<Token = u8>, <I as Stream>::Slice: AsBytes, { - trace("be_i16", move |input: I| { - be_uint::<_, u16, _>(input, 2).map(|(i, n)| (i, n as i16)) + trace("be_i16", move |input: &mut I| { + be_uint::<_, u16, _>(input, 2).map(|n| n as i16) }) .parse_next(input) } @@ -429,48 +429,48 @@ where /// # Example /// /// ```rust -/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed}; +/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed}; /// # use winnow::prelude::*; /// # use winnow::error::Needed::Size; /// use winnow::binary::be_i24; /// /// fn parser(s: &[u8]) -> IResult<&[u8], i32> { -/// be_i24.parse_next(s) +/// be_i24.parse_peek(s) /// } /// /// assert_eq!(parser(&b"\x00\x03\x05abcefg"[..]), Ok((&b"abcefg"[..], 0x000305))); -/// assert_eq!(parser(&b"\x01"[..]), Err(ErrMode::Backtrack(Error::new(&[0x01][..], ErrorKind::Slice)))); +/// assert_eq!(parser(&b"\x01"[..]), Err(ErrMode::Backtrack(InputError::new(&[0x01][..], ErrorKind::Slice)))); /// ``` /// /// ```rust -/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed}; +/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed}; /// # use winnow::prelude::*; /// # use winnow::Partial; /// use winnow::binary::be_i24; /// /// fn parser(s: Partial<&[u8]>) -> IResult<Partial<&[u8]>, i32> { -/// be_i24.parse_next(s) +/// be_i24.parse_peek(s) /// } /// /// assert_eq!(parser(Partial::new(&b"\x00\x01\x02abcd"[..])), Ok((Partial::new(&b"abcd"[..]), 0x000102))); /// assert_eq!(parser(Partial::new(&b""[..])), Err(ErrMode::Incomplete(Needed::new(3)))); /// ``` #[inline(always)] -pub fn be_i24<I, E: ParseError<I>>(input: I) -> IResult<I, i32, E> +pub fn be_i24<I, E: ParserError<I>>(input: &mut I) -> PResult<i32, E> where I: StreamIsPartial, I: Stream<Token = u8>, <I as Stream>::Slice: AsBytes, { - trace("be_i24", move |input: I| { - be_uint::<_, u32, _>(input, 3).map(|(i, n)| { + trace("be_i24", move |input: &mut I| { + be_uint::<_, u32, _>(input, 3).map(|n| { // Same as the unsigned version but we need to sign-extend manually here let n = if n & 0x80_00_00 != 0 { (n | 0xff_00_00_00) as i32 } else { n as i32 }; - (i, n) + n }) }) .parse_next(input) @@ -485,41 +485,41 @@ where /// # Example /// /// ```rust -/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed}; +/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed}; /// # use winnow::prelude::*; /// # use winnow::error::Needed::Size; /// use winnow::binary::be_i32; /// /// fn parser(s: &[u8]) -> IResult<&[u8], i32> { -/// be_i32.parse_next(s) +/// be_i32.parse_peek(s) /// } /// /// assert_eq!(parser(&b"\x00\x03\x05\x07abcefg"[..]), Ok((&b"abcefg"[..], 0x00030507))); -/// assert_eq!(parser(&b"\x01"[..]), Err(ErrMode::Backtrack(Error::new(&[0x01][..], ErrorKind::Slice)))); +/// assert_eq!(parser(&b"\x01"[..]), Err(ErrMode::Backtrack(InputError::new(&[0x01][..], ErrorKind::Slice)))); /// ``` /// /// ```rust -/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed}; +/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed}; /// # use winnow::prelude::*; /// # use winnow::Partial; /// use winnow::binary::be_i32; /// /// fn parser(s: Partial<&[u8]>) -> IResult<Partial<&[u8]>, i32> { -/// be_i32.parse_next(s) +/// be_i32.parse_peek(s) /// } /// /// assert_eq!(parser(Partial::new(&b"\x00\x01\x02\x03abcd"[..])), Ok((Partial::new(&b"abcd"[..]), 0x00010203))); /// assert_eq!(parser(Partial::new(&b""[..])), Err(ErrMode::Incomplete(Needed::new(4)))); /// ``` #[inline(always)] -pub fn be_i32<I, E: ParseError<I>>(input: I) -> IResult<I, i32, E> +pub fn be_i32<I, E: ParserError<I>>(input: &mut I) -> PResult<i32, E> where I: StreamIsPartial, I: Stream<Token = u8>, <I as Stream>::Slice: AsBytes, { - trace("be_i32", move |input: I| { - be_uint::<_, u32, _>(input, 4).map(|(i, n)| (i, n as i32)) + trace("be_i32", move |input: &mut I| { + be_uint::<_, u32, _>(input, 4).map(|n| n as i32) }) .parse_next(input) } @@ -533,41 +533,41 @@ where /// # Example /// /// ```rust -/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed}; +/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed}; /// # use winnow::prelude::*; /// # use winnow::error::Needed::Size; /// use winnow::binary::be_i64; /// /// fn parser(s: &[u8]) -> IResult<&[u8], i64> { -/// be_i64.parse_next(s) +/// be_i64.parse_peek(s) /// } /// /// assert_eq!(parser(&b"\x00\x01\x02\x03\x04\x05\x06\x07abcefg"[..]), Ok((&b"abcefg"[..], 0x0001020304050607))); -/// assert_eq!(parser(&b"\x01"[..]), Err(ErrMode::Backtrack(Error::new(&[0x01][..], ErrorKind::Slice)))); +/// assert_eq!(parser(&b"\x01"[..]), Err(ErrMode::Backtrack(InputError::new(&[0x01][..], ErrorKind::Slice)))); /// ``` /// /// ```rust -/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed}; +/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed}; /// # use winnow::prelude::*; /// # use winnow::Partial; /// use winnow::binary::be_i64; /// /// fn parser(s: Partial<&[u8]>) -> IResult<Partial<&[u8]>, i64> { -/// be_i64.parse_next(s) +/// be_i64.parse_peek(s) /// } /// /// assert_eq!(parser(Partial::new(&b"\x00\x01\x02\x03\x04\x05\x06\x07abcd"[..])), Ok((Partial::new(&b"abcd"[..]), 0x0001020304050607))); /// assert_eq!(parser(Partial::new(&b"\x01"[..])), Err(ErrMode::Incomplete(Needed::new(7)))); /// ``` #[inline(always)] -pub fn be_i64<I, E: ParseError<I>>(input: I) -> IResult<I, i64, E> +pub fn be_i64<I, E: ParserError<I>>(input: &mut I) -> PResult<i64, E> where I: StreamIsPartial, I: Stream<Token = u8>, <I as Stream>::Slice: AsBytes, { - trace("be_i64", move |input: I| { - be_uint::<_, u64, _>(input, 8).map(|(i, n)| (i, n as i64)) + trace("be_i64", move |input: &mut I| { + be_uint::<_, u64, _>(input, 8).map(|n| n as i64) }) .parse_next(input) } @@ -581,41 +581,41 @@ where /// # Example /// /// ```rust -/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed}; +/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed}; /// # use winnow::prelude::*; /// # use winnow::error::Needed::Size; /// use winnow::binary::be_i128; /// /// fn parser(s: &[u8]) -> IResult<&[u8], i128> { -/// be_i128.parse_next(s) +/// be_i128.parse_peek(s) /// } /// /// assert_eq!(parser(&b"\x00\x01\x02\x03\x04\x05\x06\x07\x00\x01\x02\x03\x04\x05\x06\x07abcefg"[..]), Ok((&b"abcefg"[..], 0x00010203040506070001020304050607))); -/// assert_eq!(parser(&b"\x01"[..]), Err(ErrMode::Backtrack(Error::new(&[0x01][..], ErrorKind::Slice)))); +/// assert_eq!(parser(&b"\x01"[..]), Err(ErrMode::Backtrack(InputError::new(&[0x01][..], ErrorKind::Slice)))); /// ``` /// /// ```rust -/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed}; +/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed}; /// # use winnow::prelude::*; /// # use winnow::Partial; /// use winnow::binary::be_i128; /// /// fn parser(s: Partial<&[u8]>) -> IResult<Partial<&[u8]>, i128> { -/// be_i128.parse_next(s) +/// be_i128.parse_peek(s) /// } /// /// assert_eq!(parser(Partial::new(&b"\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x10\x11\x12\x13\x14\x15abcd"[..])), Ok((Partial::new(&b"abcd"[..]), 0x00010203040506070809101112131415))); /// assert_eq!(parser(Partial::new(&b"\x01"[..])), Err(ErrMode::Incomplete(Needed::new(15)))); /// ``` #[inline(always)] -pub fn be_i128<I, E: ParseError<I>>(input: I) -> IResult<I, i128, E> +pub fn be_i128<I, E: ParserError<I>>(input: &mut I) -> PResult<i128, E> where I: StreamIsPartial, I: Stream<Token = u8>, <I as Stream>::Slice: AsBytes, { - trace("be_i128", move |input: I| { - be_uint::<_, u128, _>(input, 16).map(|(i, n)| (i, n as i128)) + trace("be_i128", move |input: &mut I| { + be_uint::<_, u128, _>(input, 16).map(|n| n as i128) }) .parse_next(input) } @@ -629,34 +629,34 @@ where /// # Example /// /// ```rust -/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed}; +/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed}; /// # use winnow::prelude::*; /// # use winnow::error::Needed::Size; /// use winnow::binary::le_u8; /// /// fn parser(s: &[u8]) -> IResult<&[u8], u8> { -/// le_u8.parse_next(s) +/// le_u8.parse_peek(s) /// } /// /// assert_eq!(parser(&b"\x00\x03abcefg"[..]), Ok((&b"\x03abcefg"[..], 0x00))); -/// assert_eq!(parser(&b""[..]), Err(ErrMode::Backtrack(Error::new(&[][..], ErrorKind::Token)))); +/// assert_eq!(parser(&b""[..]), Err(ErrMode::Backtrack(InputError::new(&[][..], ErrorKind::Token)))); /// ``` /// /// ```rust -/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed}; +/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed}; /// # use winnow::prelude::*; /// # use winnow::Partial; /// use winnow::binary::le_u8; /// /// fn parser(s: Partial<&[u8]>) -> IResult<Partial<&[u8]>, u8> { -/// le_u8.parse_next(s) +/// le_u8.parse_peek(s) /// } /// /// assert_eq!(parser(Partial::new(&b"\x00\x01abcd"[..])), Ok((Partial::new(&b"\x01abcd"[..]), 0x00))); /// assert_eq!(parser(Partial::new(&b""[..])), Err(ErrMode::Incomplete(Needed::new(1)))); /// ``` #[inline(always)] -pub fn le_u8<I, E: ParseError<I>>(input: I) -> IResult<I, u8, E> +pub fn le_u8<I, E: ParserError<I>>(input: &mut I) -> PResult<u8, E> where I: StreamIsPartial, I: Stream<Token = u8>, @@ -673,40 +673,40 @@ where /// # Example /// /// ```rust -/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed}; +/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed}; /// # use winnow::prelude::*; /// # use winnow::error::Needed::Size; /// use winnow::binary::le_u16; /// /// fn parser(s: &[u8]) -> IResult<&[u8], u16> { -/// le_u16.parse_next(s) +/// le_u16.parse_peek(s) /// } /// /// assert_eq!(parser(&b"\x00\x03abcefg"[..]), Ok((&b"abcefg"[..], 0x0300))); -/// assert_eq!(parser(&b"\x01"[..]), Err(ErrMode::Backtrack(Error::new(&[0x01][..], ErrorKind::Slice)))); +/// assert_eq!(parser(&b"\x01"[..]), Err(ErrMode::Backtrack(InputError::new(&[0x01][..], ErrorKind::Slice)))); /// ``` /// /// ```rust -/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed}; +/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed}; /// # use winnow::prelude::*; /// # use winnow::Partial; /// use winnow::binary::le_u16; /// /// fn parser(s: Partial<&[u8]>) -> IResult<Partial<&[u8]>, u16> { -/// le_u16::<_, Error<_>>.parse_next(s) +/// le_u16::<_, InputError<_>>.parse_peek(s) /// } /// /// assert_eq!(parser(Partial::new(&b"\x00\x01abcd"[..])), Ok((Partial::new(&b"abcd"[..]), 0x0100))); /// assert_eq!(parser(Partial::new(&b"\x01"[..])), Err(ErrMode::Incomplete(Needed::new(1)))); /// ``` #[inline(always)] -pub fn le_u16<I, E: ParseError<I>>(input: I) -> IResult<I, u16, E> +pub fn le_u16<I, E: ParserError<I>>(input: &mut I) -> PResult<u16, E> where I: StreamIsPartial, I: Stream<Token = u8>, <I as Stream>::Slice: AsBytes, { - trace("le_u16", move |input: I| le_uint(input, 2)).parse_next(input) + trace("le_u16", move |input: &mut I| le_uint(input, 2)).parse_next(input) } /// Recognizes a little endian unsigned 3 byte integer. @@ -718,40 +718,40 @@ where /// # Example /// /// ```rust -/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed}; +/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed}; /// # use winnow::prelude::*; /// # use winnow::error::Needed::Size; /// use winnow::binary::le_u24; /// /// fn parser(s: &[u8]) -> IResult<&[u8], u32> { -/// le_u24.parse_next(s) +/// le_u24.parse_peek(s) /// } /// /// assert_eq!(parser(&b"\x00\x03\x05abcefg"[..]), Ok((&b"abcefg"[..], 0x050300))); -/// assert_eq!(parser(&b"\x01"[..]), Err(ErrMode::Backtrack(Error::new(&[0x01][..], ErrorKind::Slice)))); +/// assert_eq!(parser(&b"\x01"[..]), Err(ErrMode::Backtrack(InputError::new(&[0x01][..], ErrorKind::Slice)))); /// ``` /// /// ```rust -/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed}; +/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed}; /// # use winnow::prelude::*; /// # use winnow::Partial; /// use winnow::binary::le_u24; /// /// fn parser(s: Partial<&[u8]>) -> IResult<Partial<&[u8]>, u32> { -/// le_u24::<_, Error<_>>.parse_next(s) +/// le_u24::<_, InputError<_>>.parse_peek(s) /// } /// /// assert_eq!(parser(Partial::new(&b"\x00\x01\x02abcd"[..])), Ok((Partial::new(&b"abcd"[..]), 0x020100))); /// assert_eq!(parser(Partial::new(&b"\x01"[..])), Err(ErrMode::Incomplete(Needed::new(2)))); /// ``` #[inline(always)] -pub fn le_u24<I, E: ParseError<I>>(input: I) -> IResult<I, u32, E> +pub fn le_u24<I, E: ParserError<I>>(input: &mut I) -> PResult<u32, E> where I: StreamIsPartial, I: Stream<Token = u8>, <I as Stream>::Slice: AsBytes, { - trace("le_u24", move |input: I| le_uint(input, 3)).parse_next(input) + trace("le_u24", move |input: &mut I| le_uint(input, 3)).parse_next(input) } /// Recognizes a little endian unsigned 4 bytes integer. @@ -763,40 +763,40 @@ where /// # Example /// /// ```rust -/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed}; +/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed}; /// # use winnow::prelude::*; /// # use winnow::error::Needed::Size; /// use winnow::binary::le_u32; /// /// fn parser(s: &[u8]) -> IResult<&[u8], u32> { -/// le_u32.parse_next(s) +/// le_u32.parse_peek(s) /// } /// /// assert_eq!(parser(&b"\x00\x03\x05\x07abcefg"[..]), Ok((&b"abcefg"[..], 0x07050300))); -/// assert_eq!(parser(&b"\x01"[..]), Err(ErrMode::Backtrack(Error::new(&[0x01][..], ErrorKind::Slice)))); +/// assert_eq!(parser(&b"\x01"[..]), Err(ErrMode::Backtrack(InputError::new(&[0x01][..], ErrorKind::Slice)))); /// ``` /// /// ```rust -/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed}; +/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed}; /// # use winnow::prelude::*; /// # use winnow::Partial; /// use winnow::binary::le_u32; /// /// fn parser(s: Partial<&[u8]>) -> IResult<Partial<&[u8]>, u32> { -/// le_u32::<_, Error<_>>.parse_next(s) +/// le_u32::<_, InputError<_>>.parse_peek(s) /// } /// /// assert_eq!(parser(Partial::new(&b"\x00\x01\x02\x03abcd"[..])), Ok((Partial::new(&b"abcd"[..]), 0x03020100))); /// assert_eq!(parser(Partial::new(&b"\x01"[..])), Err(ErrMode::Incomplete(Needed::new(3)))); /// ``` #[inline(always)] -pub fn le_u32<I, E: ParseError<I>>(input: I) -> IResult<I, u32, E> +pub fn le_u32<I, E: ParserError<I>>(input: &mut I) -> PResult<u32, E> where I: StreamIsPartial, I: Stream<Token = u8>, <I as Stream>::Slice: AsBytes, { - trace("le_u32", move |input: I| le_uint(input, 4)).parse_next(input) + trace("le_u32", move |input: &mut I| le_uint(input, 4)).parse_next(input) } /// Recognizes a little endian unsigned 8 bytes integer. @@ -808,40 +808,40 @@ where /// # Example /// /// ```rust -/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed}; +/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed}; /// # use winnow::prelude::*; /// # use winnow::error::Needed::Size; /// use winnow::binary::le_u64; /// /// fn parser(s: &[u8]) -> IResult<&[u8], u64> { -/// le_u64.parse_next(s) +/// le_u64.parse_peek(s) /// } /// /// assert_eq!(parser(&b"\x00\x01\x02\x03\x04\x05\x06\x07abcefg"[..]), Ok((&b"abcefg"[..], 0x0706050403020100))); -/// assert_eq!(parser(&b"\x01"[..]), Err(ErrMode::Backtrack(Error::new(&[0x01][..], ErrorKind::Slice)))); +/// assert_eq!(parser(&b"\x01"[..]), Err(ErrMode::Backtrack(InputError::new(&[0x01][..], ErrorKind::Slice)))); /// ``` /// /// ```rust -/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed}; +/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed}; /// # use winnow::prelude::*; /// # use winnow::Partial; /// use winnow::binary::le_u64; /// /// fn parser(s: Partial<&[u8]>) -> IResult<Partial<&[u8]>, u64> { -/// le_u64::<_, Error<_>>.parse_next(s) +/// le_u64::<_, InputError<_>>.parse_peek(s) /// } /// /// assert_eq!(parser(Partial::new(&b"\x00\x01\x02\x03\x04\x05\x06\x07abcd"[..])), Ok((Partial::new(&b"abcd"[..]), 0x0706050403020100))); /// assert_eq!(parser(Partial::new(&b"\x01"[..])), Err(ErrMode::Incomplete(Needed::new(7)))); /// ``` #[inline(always)] -pub fn le_u64<I, E: ParseError<I>>(input: I) -> IResult<I, u64, E> +pub fn le_u64<I, E: ParserError<I>>(input: &mut I) -> PResult<u64, E> where I: StreamIsPartial, I: Stream<Token = u8>, <I as Stream>::Slice: AsBytes, { - trace("le_u64", move |input: I| le_uint(input, 8)).parse_next(input) + trace("le_u64", move |input: &mut I| le_uint(input, 8)).parse_next(input) } /// Recognizes a little endian unsigned 16 bytes integer. @@ -853,44 +853,44 @@ where /// # Example /// /// ```rust -/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed}; +/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed}; /// # use winnow::prelude::*; /// # use winnow::error::Needed::Size; /// use winnow::binary::le_u128; /// /// fn parser(s: &[u8]) -> IResult<&[u8], u128> { -/// le_u128.parse_next(s) +/// le_u128.parse_peek(s) /// } /// /// assert_eq!(parser(&b"\x00\x01\x02\x03\x04\x05\x06\x07\x00\x01\x02\x03\x04\x05\x06\x07abcefg"[..]), Ok((&b"abcefg"[..], 0x07060504030201000706050403020100))); -/// assert_eq!(parser(&b"\x01"[..]), Err(ErrMode::Backtrack(Error::new(&[0x01][..], ErrorKind::Slice)))); +/// assert_eq!(parser(&b"\x01"[..]), Err(ErrMode::Backtrack(InputError::new(&[0x01][..], ErrorKind::Slice)))); /// ``` /// /// ```rust -/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed}; +/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed}; /// # use winnow::prelude::*; /// # use winnow::Partial; /// use winnow::binary::le_u128; /// /// fn parser(s: Partial<&[u8]>) -> IResult<Partial<&[u8]>, u128> { -/// le_u128::<_, Error<_>>.parse_next(s) +/// le_u128::<_, InputError<_>>.parse_peek(s) /// } /// /// assert_eq!(parser(Partial::new(&b"\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x10\x11\x12\x13\x14\x15abcd"[..])), Ok((Partial::new(&b"abcd"[..]), 0x15141312111009080706050403020100))); /// assert_eq!(parser(Partial::new(&b"\x01"[..])), Err(ErrMode::Incomplete(Needed::new(15)))); /// ``` #[inline(always)] -pub fn le_u128<I, E: ParseError<I>>(input: I) -> IResult<I, u128, E> +pub fn le_u128<I, E: ParserError<I>>(input: &mut I) -> PResult<u128, E> where I: StreamIsPartial, I: Stream<Token = u8>, <I as Stream>::Slice: AsBytes, { - trace("le_u128", move |input: I| le_uint(input, 16)).parse_next(input) + trace("le_u128", move |input: &mut I| le_uint(input, 16)).parse_next(input) } #[inline] -fn le_uint<I, Uint, E: ParseError<I>>(input: I, bound: usize) -> IResult<I, Uint, E> +fn le_uint<I, Uint, E: ParserError<I>>(input: &mut I, bound: usize) -> PResult<Uint, E> where I: StreamIsPartial, I: Stream<Token = u8>, @@ -924,34 +924,34 @@ where /// # Example /// /// ```rust -/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed}; +/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed}; /// # use winnow::prelude::*; /// # use winnow::error::Needed::Size; /// use winnow::binary::le_i8; /// /// fn parser(s: &[u8]) -> IResult<&[u8], i8> { -/// le_i8.parse_next(s) +/// le_i8.parse_peek(s) /// } /// /// assert_eq!(parser(&b"\x00\x03abcefg"[..]), Ok((&b"\x03abcefg"[..], 0x00))); -/// assert_eq!(parser(&b""[..]), Err(ErrMode::Backtrack(Error::new(&[][..], ErrorKind::Token)))); +/// assert_eq!(parser(&b""[..]), Err(ErrMode::Backtrack(InputError::new(&[][..], ErrorKind::Token)))); /// ``` /// /// ```rust -/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed}; +/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed}; /// # use winnow::prelude::*; /// # use winnow::Partial; /// use winnow::binary::le_i8; /// /// fn parser(s: Partial<&[u8]>) -> IResult<Partial<&[u8]>, i8> { -/// le_i8.parse_next(s) +/// le_i8.parse_peek(s) /// } /// /// assert_eq!(parser(Partial::new(&b"\x00\x01abcd"[..])), Ok((Partial::new(&b"\x01abcd"[..]), 0x00))); /// assert_eq!(parser(Partial::new(&b""[..])), Err(ErrMode::Incomplete(Needed::new(1)))); /// ``` #[inline(always)] -pub fn le_i8<I, E: ParseError<I>>(input: I) -> IResult<I, i8, E> +pub fn le_i8<I, E: ParserError<I>>(input: &mut I) -> PResult<i8, E> where I: StreamIsPartial, I: Stream<Token = u8>, @@ -968,41 +968,41 @@ where /// # Example /// /// ```rust -/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed}; +/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed}; /// # use winnow::prelude::*; /// # use winnow::error::Needed::Size; /// use winnow::binary::le_i16; /// /// fn parser(s: &[u8]) -> IResult<&[u8], i16> { -/// le_i16.parse_next(s) +/// le_i16.parse_peek(s) /// } /// /// assert_eq!(parser(&b"\x00\x03abcefg"[..]), Ok((&b"abcefg"[..], 0x0300))); -/// assert_eq!(parser(&b"\x01"[..]), Err(ErrMode::Backtrack(Error::new(&[0x01][..], ErrorKind::Slice)))); +/// assert_eq!(parser(&b"\x01"[..]), Err(ErrMode::Backtrack(InputError::new(&[0x01][..], ErrorKind::Slice)))); /// ``` /// /// ```rust -/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed}; +/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed}; /// # use winnow::prelude::*; /// # use winnow::Partial; /// use winnow::binary::le_i16; /// /// fn parser(s: Partial<&[u8]>) -> IResult<Partial<&[u8]>, i16> { -/// le_i16::<_, Error<_>>.parse_next(s) +/// le_i16::<_, InputError<_>>.parse_peek(s) /// } /// /// assert_eq!(parser(Partial::new(&b"\x00\x01abcd"[..])), Ok((Partial::new(&b"abcd"[..]), 0x0100))); /// assert_eq!(parser(Partial::new(&b"\x01"[..])), Err(ErrMode::Incomplete(Needed::new(1)))); /// ``` #[inline(always)] -pub fn le_i16<I, E: ParseError<I>>(input: I) -> IResult<I, i16, E> +pub fn le_i16<I, E: ParserError<I>>(input: &mut I) -> PResult<i16, E> where I: StreamIsPartial, I: Stream<Token = u8>, <I as Stream>::Slice: AsBytes, { - trace("le_i16", move |input: I| { - le_uint::<_, u16, _>(input, 2).map(|(i, n)| (i, n as i16)) + trace("le_i16", move |input: &mut I| { + le_uint::<_, u16, _>(input, 2).map(|n| n as i16) }) .parse_next(input) } @@ -1016,48 +1016,48 @@ where /// # Example /// /// ```rust -/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed}; +/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed}; /// # use winnow::prelude::*; /// # use winnow::error::Needed::Size; /// use winnow::binary::le_i24; /// /// fn parser(s: &[u8]) -> IResult<&[u8], i32> { -/// le_i24.parse_next(s) +/// le_i24.parse_peek(s) /// } /// /// assert_eq!(parser(&b"\x00\x03\x05abcefg"[..]), Ok((&b"abcefg"[..], 0x050300))); -/// assert_eq!(parser(&b"\x01"[..]), Err(ErrMode::Backtrack(Error::new(&[0x01][..], ErrorKind::Slice)))); +/// assert_eq!(parser(&b"\x01"[..]), Err(ErrMode::Backtrack(InputError::new(&[0x01][..], ErrorKind::Slice)))); /// ``` /// /// ```rust -/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed}; +/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed}; /// # use winnow::prelude::*; /// # use winnow::Partial; /// use winnow::binary::le_i24; /// /// fn parser(s: Partial<&[u8]>) -> IResult<Partial<&[u8]>, i32> { -/// le_i24::<_, Error<_>>.parse_next(s) +/// le_i24::<_, InputError<_>>.parse_peek(s) /// } /// /// assert_eq!(parser(Partial::new(&b"\x00\x01\x02abcd"[..])), Ok((Partial::new(&b"abcd"[..]), 0x020100))); /// assert_eq!(parser(Partial::new(&b"\x01"[..])), Err(ErrMode::Incomplete(Needed::new(2)))); /// ``` #[inline(always)] -pub fn le_i24<I, E: ParseError<I>>(input: I) -> IResult<I, i32, E> +pub fn le_i24<I, E: ParserError<I>>(input: &mut I) -> PResult<i32, E> where I: StreamIsPartial, I: Stream<Token = u8>, <I as Stream>::Slice: AsBytes, { - trace("le_i24", move |input: I| { - le_uint::<_, u32, _>(input, 3).map(|(i, n)| { + trace("le_i24", move |input: &mut I| { + le_uint::<_, u32, _>(input, 3).map(|n| { // Same as the unsigned version but we need to sign-extend manually here let n = if n & 0x80_00_00 != 0 { (n | 0xff_00_00_00) as i32 } else { n as i32 }; - (i, n) + n }) }) .parse_next(input) @@ -1072,41 +1072,41 @@ where /// # Example /// /// ```rust -/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed}; +/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed}; /// # use winnow::prelude::*; /// # use winnow::error::Needed::Size; /// use winnow::binary::le_i32; /// /// fn parser(s: &[u8]) -> IResult<&[u8], i32> { -/// le_i32.parse_next(s) +/// le_i32.parse_peek(s) /// } /// /// assert_eq!(parser(&b"\x00\x03\x05\x07abcefg"[..]), Ok((&b"abcefg"[..], 0x07050300))); -/// assert_eq!(parser(&b"\x01"[..]), Err(ErrMode::Backtrack(Error::new(&[0x01][..], ErrorKind::Slice)))); +/// assert_eq!(parser(&b"\x01"[..]), Err(ErrMode::Backtrack(InputError::new(&[0x01][..], ErrorKind::Slice)))); /// ``` /// /// ```rust -/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed}; +/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed}; /// # use winnow::prelude::*; /// # use winnow::Partial; /// use winnow::binary::le_i32; /// /// fn parser(s: Partial<&[u8]>) -> IResult<Partial<&[u8]>, i32> { -/// le_i32::<_, Error<_>>.parse_next(s) +/// le_i32::<_, InputError<_>>.parse_peek(s) /// } /// /// assert_eq!(parser(Partial::new(&b"\x00\x01\x02\x03abcd"[..])), Ok((Partial::new(&b"abcd"[..]), 0x03020100))); /// assert_eq!(parser(Partial::new(&b"\x01"[..])), Err(ErrMode::Incomplete(Needed::new(3)))); /// ``` #[inline(always)] -pub fn le_i32<I, E: ParseError<I>>(input: I) -> IResult<I, i32, E> +pub fn le_i32<I, E: ParserError<I>>(input: &mut I) -> PResult<i32, E> where I: StreamIsPartial, I: Stream<Token = u8>, <I as Stream>::Slice: AsBytes, { - trace("le_i32", move |input: I| { - le_uint::<_, u32, _>(input, 4).map(|(i, n)| (i, n as i32)) + trace("le_i32", move |input: &mut I| { + le_uint::<_, u32, _>(input, 4).map(|n| n as i32) }) .parse_next(input) } @@ -1120,41 +1120,41 @@ where /// # Example /// /// ```rust -/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed}; +/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed}; /// # use winnow::prelude::*; /// # use winnow::error::Needed::Size; /// use winnow::binary::le_i64; /// /// fn parser(s: &[u8]) -> IResult<&[u8], i64> { -/// le_i64.parse_next(s) +/// le_i64.parse_peek(s) /// } /// /// assert_eq!(parser(&b"\x00\x01\x02\x03\x04\x05\x06\x07abcefg"[..]), Ok((&b"abcefg"[..], 0x0706050403020100))); -/// assert_eq!(parser(&b"\x01"[..]), Err(ErrMode::Backtrack(Error::new(&[0x01][..], ErrorKind::Slice)))); +/// assert_eq!(parser(&b"\x01"[..]), Err(ErrMode::Backtrack(InputError::new(&[0x01][..], ErrorKind::Slice)))); /// ``` /// /// ```rust -/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed}; +/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed}; /// # use winnow::prelude::*; /// # use winnow::Partial; /// use winnow::binary::le_i64; /// /// fn parser(s: Partial<&[u8]>) -> IResult<Partial<&[u8]>, i64> { -/// le_i64::<_, Error<_>>.parse_next(s) +/// le_i64::<_, InputError<_>>.parse_peek(s) /// } /// /// assert_eq!(parser(Partial::new(&b"\x00\x01\x02\x03\x04\x05\x06\x07abcd"[..])), Ok((Partial::new(&b"abcd"[..]), 0x0706050403020100))); /// assert_eq!(parser(Partial::new(&b"\x01"[..])), Err(ErrMode::Incomplete(Needed::new(7)))); /// ``` #[inline(always)] -pub fn le_i64<I, E: ParseError<I>>(input: I) -> IResult<I, i64, E> +pub fn le_i64<I, E: ParserError<I>>(input: &mut I) -> PResult<i64, E> where I: StreamIsPartial, I: Stream<Token = u8>, <I as Stream>::Slice: AsBytes, { - trace("le_i64", move |input: I| { - le_uint::<_, u64, _>(input, 8).map(|(i, n)| (i, n as i64)) + trace("le_i64", move |input: &mut I| { + le_uint::<_, u64, _>(input, 8).map(|n| n as i64) }) .parse_next(input) } @@ -1168,41 +1168,41 @@ where /// # Example /// /// ```rust -/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed}; +/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed}; /// # use winnow::prelude::*; /// # use winnow::error::Needed::Size; /// use winnow::binary::le_i128; /// /// fn parser(s: &[u8]) -> IResult<&[u8], i128> { -/// le_i128.parse_next(s) +/// le_i128.parse_peek(s) /// } /// /// assert_eq!(parser(&b"\x00\x01\x02\x03\x04\x05\x06\x07\x00\x01\x02\x03\x04\x05\x06\x07abcefg"[..]), Ok((&b"abcefg"[..], 0x07060504030201000706050403020100))); -/// assert_eq!(parser(&b"\x01"[..]), Err(ErrMode::Backtrack(Error::new(&[0x01][..], ErrorKind::Slice)))); +/// assert_eq!(parser(&b"\x01"[..]), Err(ErrMode::Backtrack(InputError::new(&[0x01][..], ErrorKind::Slice)))); /// ``` /// /// ```rust -/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed}; +/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed}; /// # use winnow::prelude::*; /// # use winnow::Partial; /// use winnow::binary::le_i128; /// /// fn parser(s: Partial<&[u8]>) -> IResult<Partial<&[u8]>, i128> { -/// le_i128::<_, Error<_>>.parse_next(s) +/// le_i128::<_, InputError<_>>.parse_peek(s) /// } /// /// assert_eq!(parser(Partial::new(&b"\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x10\x11\x12\x13\x14\x15abcd"[..])), Ok((Partial::new(&b"abcd"[..]), 0x15141312111009080706050403020100))); /// assert_eq!(parser(Partial::new(&b"\x01"[..])), Err(ErrMode::Incomplete(Needed::new(15)))); /// ``` #[inline(always)] -pub fn le_i128<I, E: ParseError<I>>(input: I) -> IResult<I, i128, E> +pub fn le_i128<I, E: ParserError<I>>(input: &mut I) -> PResult<i128, E> where I: StreamIsPartial, I: Stream<Token = u8>, <I as Stream>::Slice: AsBytes, { - trace("le_i128", move |input: I| { - le_uint::<_, u128, _>(input, 16).map(|(i, n)| (i, n as i128)) + trace("le_i128", move |input: &mut I| { + le_uint::<_, u128, _>(input, 16).map(|n| n as i128) }) .parse_next(input) } @@ -1218,40 +1218,40 @@ where /// # Example /// /// ```rust -/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed}; +/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed}; /// # use winnow::prelude::*; /// # use winnow::error::Needed::Size; /// use winnow::binary::u8; /// /// fn parser(s: &[u8]) -> IResult<&[u8], u8> { -/// u8.parse_next(s) +/// u8.parse_peek(s) /// } /// /// assert_eq!(parser(&b"\x00\x03abcefg"[..]), Ok((&b"\x03abcefg"[..], 0x00))); -/// assert_eq!(parser(&b""[..]), Err(ErrMode::Backtrack(Error::new(&[][..], ErrorKind::Token)))); +/// assert_eq!(parser(&b""[..]), Err(ErrMode::Backtrack(InputError::new(&[][..], ErrorKind::Token)))); /// ``` /// /// ```rust -/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed}; +/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed}; /// # use winnow::prelude::*; /// # use winnow::error::Needed::Size; /// # use winnow::Partial; /// use winnow::binary::u8; /// /// fn parser(s: Partial<&[u8]>) -> IResult<Partial<&[u8]>, u8> { -/// u8::<_, Error<_>>.parse_next(s) +/// u8::<_, InputError<_>>.parse_peek(s) /// } /// /// assert_eq!(parser(Partial::new(&b"\x00\x03abcefg"[..])), Ok((Partial::new(&b"\x03abcefg"[..]), 0x00))); /// assert_eq!(parser(Partial::new(&b""[..])), Err(ErrMode::Incomplete(Needed::new(1)))); /// ``` #[inline(always)] -pub fn u8<I, E: ParseError<I>>(input: I) -> IResult<I, u8, E> +pub fn u8<I, E: ParserError<I>>(input: &mut I) -> PResult<u8, E> where I: StreamIsPartial, I: Stream<Token = u8>, { - trace("u8", move |input: I| { + trace("u8", move |input: &mut I| { if <I as StreamIsPartial>::is_partial_supported() { u8_::<_, _, true>(input) } else { @@ -1261,7 +1261,7 @@ where .parse_next(input) } -fn u8_<I, E: ParseError<I>, const PARTIAL: bool>(input: I) -> IResult<I, u8, E> +fn u8_<I, E: ParserError<I>, const PARTIAL: bool>(input: &mut I) -> PResult<u8, E> where I: StreamIsPartial, I: Stream<Token = u8>, @@ -1287,55 +1287,55 @@ where /// # Example /// /// ```rust -/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed}; +/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed}; /// # use winnow::prelude::*; /// # use winnow::error::Needed::Size; /// use winnow::binary::u16; /// /// let be_u16 = |s| { -/// u16(winnow::binary::Endianness::Big).parse_next(s) +/// u16(winnow::binary::Endianness::Big).parse_peek(s) /// }; /// /// assert_eq!(be_u16(&b"\x00\x03abcefg"[..]), Ok((&b"abcefg"[..], 0x0003))); -/// assert_eq!(be_u16(&b"\x01"[..]), Err(ErrMode::Backtrack(Error::new(&[0x01][..], ErrorKind::Slice)))); +/// assert_eq!(be_u16(&b"\x01"[..]), Err(ErrMode::Backtrack(InputError::new(&[0x01][..], ErrorKind::Slice)))); /// /// let le_u16 = |s| { -/// u16(winnow::binary::Endianness::Little).parse_next(s) +/// u16(winnow::binary::Endianness::Little).parse_peek(s) /// }; /// /// assert_eq!(le_u16(&b"\x00\x03abcefg"[..]), Ok((&b"abcefg"[..], 0x0300))); -/// assert_eq!(le_u16(&b"\x01"[..]), Err(ErrMode::Backtrack(Error::new(&[0x01][..], ErrorKind::Slice)))); +/// assert_eq!(le_u16(&b"\x01"[..]), Err(ErrMode::Backtrack(InputError::new(&[0x01][..], ErrorKind::Slice)))); /// ``` /// /// ```rust -/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed}; +/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed}; /// # use winnow::prelude::*; /// # use winnow::error::Needed::Size; /// # use winnow::Partial; /// use winnow::binary::u16; /// /// let be_u16 = |s| { -/// u16::<_, Error<_>>(winnow::binary::Endianness::Big).parse_next(s) +/// u16::<_, InputError<_>>(winnow::binary::Endianness::Big).parse_peek(s) /// }; /// /// assert_eq!(be_u16(Partial::new(&b"\x00\x03abcefg"[..])), Ok((Partial::new(&b"abcefg"[..]), 0x0003))); /// assert_eq!(be_u16(Partial::new(&b"\x01"[..])), Err(ErrMode::Incomplete(Needed::new(1)))); /// /// let le_u16 = |s| { -/// u16::<_, Error<_>>(winnow::binary::Endianness::Little).parse_next(s) +/// u16::<_, InputError<_>>(winnow::binary::Endianness::Little).parse_peek(s) /// }; /// /// assert_eq!(le_u16(Partial::new(&b"\x00\x03abcefg"[..])), Ok((Partial::new(&b"abcefg"[..]), 0x0300))); /// assert_eq!(le_u16(Partial::new(&b"\x01"[..])), Err(ErrMode::Incomplete(Needed::new(1)))); /// ``` #[inline(always)] -pub fn u16<I, E: ParseError<I>>(endian: Endianness) -> impl Parser<I, u16, E> +pub fn u16<I, E: ParserError<I>>(endian: Endianness) -> impl Parser<I, u16, E> where I: StreamIsPartial, I: Stream<Token = u8>, <I as Stream>::Slice: AsBytes, { - move |input: I| { + move |input: &mut I| { match endian { Endianness::Big => be_u16, Endianness::Little => le_u16, @@ -1359,55 +1359,55 @@ where /// # Example /// /// ```rust -/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed}; +/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed}; /// # use winnow::prelude::*; /// # use winnow::error::Needed::Size; /// use winnow::binary::u24; /// /// let be_u24 = |s| { -/// u24(winnow::binary::Endianness::Big).parse_next(s) +/// u24(winnow::binary::Endianness::Big).parse_peek(s) /// }; /// /// assert_eq!(be_u24(&b"\x00\x03\x05abcefg"[..]), Ok((&b"abcefg"[..], 0x000305))); -/// assert_eq!(be_u24(&b"\x01"[..]), Err(ErrMode::Backtrack(Error::new(&[0x01][..], ErrorKind::Slice)))); +/// assert_eq!(be_u24(&b"\x01"[..]), Err(ErrMode::Backtrack(InputError::new(&[0x01][..], ErrorKind::Slice)))); /// /// let le_u24 = |s| { -/// u24(winnow::binary::Endianness::Little).parse_next(s) +/// u24(winnow::binary::Endianness::Little).parse_peek(s) /// }; /// /// assert_eq!(le_u24(&b"\x00\x03\x05abcefg"[..]), Ok((&b"abcefg"[..], 0x050300))); -/// assert_eq!(le_u24(&b"\x01"[..]), Err(ErrMode::Backtrack(Error::new(&[0x01][..], ErrorKind::Slice)))); +/// assert_eq!(le_u24(&b"\x01"[..]), Err(ErrMode::Backtrack(InputError::new(&[0x01][..], ErrorKind::Slice)))); /// ``` /// /// ```rust -/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed}; +/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed}; /// # use winnow::prelude::*; /// # use winnow::error::Needed::Size; /// # use winnow::Partial; /// use winnow::binary::u24; /// /// let be_u24 = |s| { -/// u24::<_,Error<_>>(winnow::binary::Endianness::Big).parse_next(s) +/// u24::<_,InputError<_>>(winnow::binary::Endianness::Big).parse_peek(s) /// }; /// /// assert_eq!(be_u24(Partial::new(&b"\x00\x03\x05abcefg"[..])), Ok((Partial::new(&b"abcefg"[..]), 0x000305))); /// assert_eq!(be_u24(Partial::new(&b"\x01"[..])), Err(ErrMode::Incomplete(Needed::new(2)))); /// /// let le_u24 = |s| { -/// u24::<_, Error<_>>(winnow::binary::Endianness::Little).parse_next(s) +/// u24::<_, InputError<_>>(winnow::binary::Endianness::Little).parse_peek(s) /// }; /// /// assert_eq!(le_u24(Partial::new(&b"\x00\x03\x05abcefg"[..])), Ok((Partial::new(&b"abcefg"[..]), 0x050300))); /// assert_eq!(le_u24(Partial::new(&b"\x01"[..])), Err(ErrMode::Incomplete(Needed::new(2)))); /// ``` #[inline(always)] -pub fn u24<I, E: ParseError<I>>(endian: Endianness) -> impl Parser<I, u32, E> +pub fn u24<I, E: ParserError<I>>(endian: Endianness) -> impl Parser<I, u32, E> where I: StreamIsPartial, I: Stream<Token = u8>, <I as Stream>::Slice: AsBytes, { - move |input: I| { + move |input: &mut I| { match endian { Endianness::Big => be_u24, Endianness::Little => le_u24, @@ -1431,55 +1431,55 @@ where /// # Example /// /// ```rust -/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed}; +/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed}; /// # use winnow::prelude::*; /// # use winnow::error::Needed::Size; /// use winnow::binary::u32; /// /// let be_u32 = |s| { -/// u32(winnow::binary::Endianness::Big).parse_next(s) +/// u32(winnow::binary::Endianness::Big).parse_peek(s) /// }; /// /// assert_eq!(be_u32(&b"\x00\x03\x05\x07abcefg"[..]), Ok((&b"abcefg"[..], 0x00030507))); -/// assert_eq!(be_u32(&b"\x01"[..]), Err(ErrMode::Backtrack(Error::new(&[0x01][..], ErrorKind::Slice)))); +/// assert_eq!(be_u32(&b"\x01"[..]), Err(ErrMode::Backtrack(InputError::new(&[0x01][..], ErrorKind::Slice)))); /// /// let le_u32 = |s| { -/// u32(winnow::binary::Endianness::Little).parse_next(s) +/// u32(winnow::binary::Endianness::Little).parse_peek(s) /// }; /// /// assert_eq!(le_u32(&b"\x00\x03\x05\x07abcefg"[..]), Ok((&b"abcefg"[..], 0x07050300))); -/// assert_eq!(le_u32(&b"\x01"[..]), Err(ErrMode::Backtrack(Error::new(&[0x01][..], ErrorKind::Slice)))); +/// assert_eq!(le_u32(&b"\x01"[..]), Err(ErrMode::Backtrack(InputError::new(&[0x01][..], ErrorKind::Slice)))); /// ``` /// /// ```rust -/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed}; +/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed}; /// # use winnow::prelude::*; /// # use winnow::error::Needed::Size; /// # use winnow::Partial; /// use winnow::binary::u32; /// /// let be_u32 = |s| { -/// u32::<_, Error<_>>(winnow::binary::Endianness::Big).parse_next(s) +/// u32::<_, InputError<_>>(winnow::binary::Endianness::Big).parse_peek(s) /// }; /// /// assert_eq!(be_u32(Partial::new(&b"\x00\x03\x05\x07abcefg"[..])), Ok((Partial::new(&b"abcefg"[..]), 0x00030507))); /// assert_eq!(be_u32(Partial::new(&b"\x01"[..])), Err(ErrMode::Incomplete(Needed::new(3)))); /// /// let le_u32 = |s| { -/// u32::<_, Error<_>>(winnow::binary::Endianness::Little).parse_next(s) +/// u32::<_, InputError<_>>(winnow::binary::Endianness::Little).parse_peek(s) /// }; /// /// assert_eq!(le_u32(Partial::new(&b"\x00\x03\x05\x07abcefg"[..])), Ok((Partial::new(&b"abcefg"[..]), 0x07050300))); /// assert_eq!(le_u32(Partial::new(&b"\x01"[..])), Err(ErrMode::Incomplete(Needed::new(3)))); /// ``` #[inline(always)] -pub fn u32<I, E: ParseError<I>>(endian: Endianness) -> impl Parser<I, u32, E> +pub fn u32<I, E: ParserError<I>>(endian: Endianness) -> impl Parser<I, u32, E> where I: StreamIsPartial, I: Stream<Token = u8>, <I as Stream>::Slice: AsBytes, { - move |input: I| { + move |input: &mut I| { match endian { Endianness::Big => be_u32, Endianness::Little => le_u32, @@ -1503,55 +1503,55 @@ where /// # Example /// /// ```rust -/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed}; +/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed}; /// # use winnow::prelude::*; /// # use winnow::error::Needed::Size; /// use winnow::binary::u64; /// /// let be_u64 = |s| { -/// u64(winnow::binary::Endianness::Big).parse_next(s) +/// u64(winnow::binary::Endianness::Big).parse_peek(s) /// }; /// /// assert_eq!(be_u64(&b"\x00\x01\x02\x03\x04\x05\x06\x07abcefg"[..]), Ok((&b"abcefg"[..], 0x0001020304050607))); -/// assert_eq!(be_u64(&b"\x01"[..]), Err(ErrMode::Backtrack(Error::new(&[0x01][..], ErrorKind::Slice)))); +/// assert_eq!(be_u64(&b"\x01"[..]), Err(ErrMode::Backtrack(InputError::new(&[0x01][..], ErrorKind::Slice)))); /// /// let le_u64 = |s| { -/// u64(winnow::binary::Endianness::Little).parse_next(s) +/// u64(winnow::binary::Endianness::Little).parse_peek(s) /// }; /// /// assert_eq!(le_u64(&b"\x00\x01\x02\x03\x04\x05\x06\x07abcefg"[..]), Ok((&b"abcefg"[..], 0x0706050403020100))); -/// assert_eq!(le_u64(&b"\x01"[..]), Err(ErrMode::Backtrack(Error::new(&[0x01][..], ErrorKind::Slice)))); +/// assert_eq!(le_u64(&b"\x01"[..]), Err(ErrMode::Backtrack(InputError::new(&[0x01][..], ErrorKind::Slice)))); /// ``` /// /// ```rust -/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed}; +/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed}; /// # use winnow::prelude::*; /// # use winnow::error::Needed::Size; /// # use winnow::Partial; /// use winnow::binary::u64; /// /// let be_u64 = |s| { -/// u64::<_, Error<_>>(winnow::binary::Endianness::Big).parse_next(s) +/// u64::<_, InputError<_>>(winnow::binary::Endianness::Big).parse_peek(s) /// }; /// /// assert_eq!(be_u64(Partial::new(&b"\x00\x01\x02\x03\x04\x05\x06\x07abcefg"[..])), Ok((Partial::new(&b"abcefg"[..]), 0x0001020304050607))); /// assert_eq!(be_u64(Partial::new(&b"\x01"[..])), Err(ErrMode::Incomplete(Needed::new(7)))); /// /// let le_u64 = |s| { -/// u64::<_, Error<_>>(winnow::binary::Endianness::Little).parse_next(s) +/// u64::<_, InputError<_>>(winnow::binary::Endianness::Little).parse_peek(s) /// }; /// /// assert_eq!(le_u64(Partial::new(&b"\x00\x01\x02\x03\x04\x05\x06\x07abcefg"[..])), Ok((Partial::new(&b"abcefg"[..]), 0x0706050403020100))); /// assert_eq!(le_u64(Partial::new(&b"\x01"[..])), Err(ErrMode::Incomplete(Needed::new(7)))); /// ``` #[inline(always)] -pub fn u64<I, E: ParseError<I>>(endian: Endianness) -> impl Parser<I, u64, E> +pub fn u64<I, E: ParserError<I>>(endian: Endianness) -> impl Parser<I, u64, E> where I: StreamIsPartial, I: Stream<Token = u8>, <I as Stream>::Slice: AsBytes, { - move |input: I| { + move |input: &mut I| { match endian { Endianness::Big => be_u64, Endianness::Little => le_u64, @@ -1575,55 +1575,55 @@ where /// # Example /// /// ```rust -/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed}; +/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed}; /// # use winnow::prelude::*; /// # use winnow::error::Needed::Size; /// use winnow::binary::u128; /// /// let be_u128 = |s| { -/// u128(winnow::binary::Endianness::Big).parse_next(s) +/// u128(winnow::binary::Endianness::Big).parse_peek(s) /// }; /// /// assert_eq!(be_u128(&b"\x00\x01\x02\x03\x04\x05\x06\x07\x00\x01\x02\x03\x04\x05\x06\x07abcefg"[..]), Ok((&b"abcefg"[..], 0x00010203040506070001020304050607))); -/// assert_eq!(be_u128(&b"\x01"[..]), Err(ErrMode::Backtrack(Error::new(&[0x01][..], ErrorKind::Slice)))); +/// assert_eq!(be_u128(&b"\x01"[..]), Err(ErrMode::Backtrack(InputError::new(&[0x01][..], ErrorKind::Slice)))); /// /// let le_u128 = |s| { -/// u128(winnow::binary::Endianness::Little).parse_next(s) +/// u128(winnow::binary::Endianness::Little).parse_peek(s) /// }; /// /// assert_eq!(le_u128(&b"\x00\x01\x02\x03\x04\x05\x06\x07\x00\x01\x02\x03\x04\x05\x06\x07abcefg"[..]), Ok((&b"abcefg"[..], 0x07060504030201000706050403020100))); -/// assert_eq!(le_u128(&b"\x01"[..]), Err(ErrMode::Backtrack(Error::new(&[0x01][..], ErrorKind::Slice)))); +/// assert_eq!(le_u128(&b"\x01"[..]), Err(ErrMode::Backtrack(InputError::new(&[0x01][..], ErrorKind::Slice)))); /// ``` /// /// ```rust -/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed}; +/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed}; /// # use winnow::prelude::*; /// # use winnow::error::Needed::Size; /// # use winnow::Partial; /// use winnow::binary::u128; /// /// let be_u128 = |s| { -/// u128::<_, Error<_>>(winnow::binary::Endianness::Big).parse_next(s) +/// u128::<_, InputError<_>>(winnow::binary::Endianness::Big).parse_peek(s) /// }; /// /// assert_eq!(be_u128(Partial::new(&b"\x00\x01\x02\x03\x04\x05\x06\x07\x00\x01\x02\x03\x04\x05\x06\x07abcefg"[..])), Ok((Partial::new(&b"abcefg"[..]), 0x00010203040506070001020304050607))); /// assert_eq!(be_u128(Partial::new(&b"\x01"[..])), Err(ErrMode::Incomplete(Needed::new(15)))); /// /// let le_u128 = |s| { -/// u128::<_, Error<_>>(winnow::binary::Endianness::Little).parse_next(s) +/// u128::<_, InputError<_>>(winnow::binary::Endianness::Little).parse_peek(s) /// }; /// /// assert_eq!(le_u128(Partial::new(&b"\x00\x01\x02\x03\x04\x05\x06\x07\x00\x01\x02\x03\x04\x05\x06\x07abcefg"[..])), Ok((Partial::new(&b"abcefg"[..]), 0x07060504030201000706050403020100))); /// assert_eq!(le_u128(Partial::new(&b"\x01"[..])), Err(ErrMode::Incomplete(Needed::new(15)))); /// ``` #[inline(always)] -pub fn u128<I, E: ParseError<I>>(endian: Endianness) -> impl Parser<I, u128, E> +pub fn u128<I, E: ParserError<I>>(endian: Endianness) -> impl Parser<I, u128, E> where I: StreamIsPartial, I: Stream<Token = u8>, <I as Stream>::Slice: AsBytes, { - move |input: I| { + move |input: &mut I| { match endian { Endianness::Big => be_u128, Endianness::Little => le_u128, @@ -1646,46 +1646,46 @@ where /// # Example /// /// ```rust -/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed}; +/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed}; /// # use winnow::prelude::*; /// # use winnow::error::Needed::Size; /// use winnow::binary::i8; /// /// fn parser(s: &[u8]) -> IResult<&[u8], i8> { -/// i8.parse_next(s) +/// i8.parse_peek(s) /// } /// /// assert_eq!(parser(&b"\x00\x03abcefg"[..]), Ok((&b"\x03abcefg"[..], 0x00))); -/// assert_eq!(parser(&b""[..]), Err(ErrMode::Backtrack(Error::new(&[][..], ErrorKind::Token)))); +/// assert_eq!(parser(&b""[..]), Err(ErrMode::Backtrack(InputError::new(&[][..], ErrorKind::Token)))); /// ``` /// /// ```rust -/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed}; +/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed}; /// # use winnow::prelude::*; /// # use winnow::error::Needed::Size; /// # use winnow::Partial; /// use winnow::binary::i8; /// /// fn parser(s: Partial<&[u8]>) -> IResult<Partial<&[u8]>, i8> { -/// i8.parse_next(s) +/// i8.parse_peek(s) /// } /// /// assert_eq!(parser(Partial::new(&b"\x00\x03abcefg"[..])), Ok((Partial::new(&b"\x03abcefg"[..]), 0x00))); /// assert_eq!(parser(Partial::new(&b""[..])), Err(ErrMode::Incomplete(Needed::new(1)))); /// ``` #[inline(always)] -pub fn i8<I, E: ParseError<I>>(input: I) -> IResult<I, i8, E> +pub fn i8<I, E: ParserError<I>>(input: &mut I) -> PResult<i8, E> where I: StreamIsPartial, I: Stream<Token = u8>, { - trace("i8", move |input: I| { + trace("i8", move |input: &mut I| { if <I as StreamIsPartial>::is_partial_supported() { u8_::<_, _, true>(input) } else { u8_::<_, _, false>(input) } - .map(|(i, n)| (i, n as i8)) + .map(|n| n as i8) }) .parse_next(input) } @@ -1702,55 +1702,55 @@ where /// # Example /// /// ```rust -/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed}; +/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed}; /// # use winnow::prelude::*; /// # use winnow::error::Needed::Size; /// use winnow::binary::i16; /// /// let be_i16 = |s| { -/// i16(winnow::binary::Endianness::Big).parse_next(s) +/// i16(winnow::binary::Endianness::Big).parse_peek(s) /// }; /// /// assert_eq!(be_i16(&b"\x00\x03abcefg"[..]), Ok((&b"abcefg"[..], 0x0003))); -/// assert_eq!(be_i16(&b"\x01"[..]), Err(ErrMode::Backtrack(Error::new(&[0x01][..], ErrorKind::Slice)))); +/// assert_eq!(be_i16(&b"\x01"[..]), Err(ErrMode::Backtrack(InputError::new(&[0x01][..], ErrorKind::Slice)))); /// /// let le_i16 = |s| { -/// i16(winnow::binary::Endianness::Little).parse_next(s) +/// i16(winnow::binary::Endianness::Little).parse_peek(s) /// }; /// /// assert_eq!(le_i16(&b"\x00\x03abcefg"[..]), Ok((&b"abcefg"[..], 0x0300))); -/// assert_eq!(le_i16(&b"\x01"[..]), Err(ErrMode::Backtrack(Error::new(&[0x01][..], ErrorKind::Slice)))); +/// assert_eq!(le_i16(&b"\x01"[..]), Err(ErrMode::Backtrack(InputError::new(&[0x01][..], ErrorKind::Slice)))); /// ``` /// /// ```rust -/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed}; +/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed}; /// # use winnow::prelude::*; /// # use winnow::error::Needed::Size; /// # use winnow::Partial; /// use winnow::binary::i16; /// /// let be_i16 = |s| { -/// i16::<_, Error<_>>(winnow::binary::Endianness::Big).parse_next(s) +/// i16::<_, InputError<_>>(winnow::binary::Endianness::Big).parse_peek(s) /// }; /// /// assert_eq!(be_i16(Partial::new(&b"\x00\x03abcefg"[..])), Ok((Partial::new(&b"abcefg"[..]), 0x0003))); /// assert_eq!(be_i16(Partial::new(&b"\x01"[..])), Err(ErrMode::Incomplete(Needed::new(1)))); /// /// let le_i16 = |s| { -/// i16::<_, Error<_>>(winnow::binary::Endianness::Little).parse_next(s) +/// i16::<_, InputError<_>>(winnow::binary::Endianness::Little).parse_peek(s) /// }; /// /// assert_eq!(le_i16(Partial::new(&b"\x00\x03abcefg"[..])), Ok((Partial::new(&b"abcefg"[..]), 0x0300))); /// assert_eq!(le_i16(Partial::new(&b"\x01"[..])), Err(ErrMode::Incomplete(Needed::new(1)))); /// ``` #[inline(always)] -pub fn i16<I, E: ParseError<I>>(endian: Endianness) -> impl Parser<I, i16, E> +pub fn i16<I, E: ParserError<I>>(endian: Endianness) -> impl Parser<I, i16, E> where I: StreamIsPartial, I: Stream<Token = u8>, <I as Stream>::Slice: AsBytes, { - move |input: I| { + move |input: &mut I| { match endian { Endianness::Big => be_i16, Endianness::Little => le_i16, @@ -1774,55 +1774,55 @@ where /// # Example /// /// ```rust -/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed}; +/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed}; /// # use winnow::prelude::*; /// # use winnow::error::Needed::Size; /// use winnow::binary::i24; /// /// let be_i24 = |s| { -/// i24(winnow::binary::Endianness::Big).parse_next(s) +/// i24(winnow::binary::Endianness::Big).parse_peek(s) /// }; /// /// assert_eq!(be_i24(&b"\x00\x03\x05abcefg"[..]), Ok((&b"abcefg"[..], 0x000305))); -/// assert_eq!(be_i24(&b"\x01"[..]), Err(ErrMode::Backtrack(Error::new(&[0x01][..], ErrorKind::Slice)))); +/// assert_eq!(be_i24(&b"\x01"[..]), Err(ErrMode::Backtrack(InputError::new(&[0x01][..], ErrorKind::Slice)))); /// /// let le_i24 = |s| { -/// i24(winnow::binary::Endianness::Little).parse_next(s) +/// i24(winnow::binary::Endianness::Little).parse_peek(s) /// }; /// /// assert_eq!(le_i24(&b"\x00\x03\x05abcefg"[..]), Ok((&b"abcefg"[..], 0x050300))); -/// assert_eq!(le_i24(&b"\x01"[..]), Err(ErrMode::Backtrack(Error::new(&[0x01][..], ErrorKind::Slice)))); +/// assert_eq!(le_i24(&b"\x01"[..]), Err(ErrMode::Backtrack(InputError::new(&[0x01][..], ErrorKind::Slice)))); /// ``` /// /// ```rust -/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed}; +/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed}; /// # use winnow::prelude::*; /// # use winnow::error::Needed::Size; /// # use winnow::Partial; /// use winnow::binary::i24; /// /// let be_i24 = |s| { -/// i24::<_, Error<_>>(winnow::binary::Endianness::Big).parse_next(s) +/// i24::<_, InputError<_>>(winnow::binary::Endianness::Big).parse_peek(s) /// }; /// /// assert_eq!(be_i24(Partial::new(&b"\x00\x03\x05abcefg"[..])), Ok((Partial::new(&b"abcefg"[..]), 0x000305))); /// assert_eq!(be_i24(Partial::new(&b"\x01"[..])), Err(ErrMode::Incomplete(Needed::new(2)))); /// /// let le_i24 = |s| { -/// i24::<_, Error<_>>(winnow::binary::Endianness::Little).parse_next(s) +/// i24::<_, InputError<_>>(winnow::binary::Endianness::Little).parse_peek(s) /// }; /// /// assert_eq!(le_i24(Partial::new(&b"\x00\x03\x05abcefg"[..])), Ok((Partial::new(&b"abcefg"[..]), 0x050300))); /// assert_eq!(le_i24(Partial::new(&b"\x01"[..])), Err(ErrMode::Incomplete(Needed::new(2)))); /// ``` #[inline(always)] -pub fn i24<I, E: ParseError<I>>(endian: Endianness) -> impl Parser<I, i32, E> +pub fn i24<I, E: ParserError<I>>(endian: Endianness) -> impl Parser<I, i32, E> where I: StreamIsPartial, I: Stream<Token = u8>, <I as Stream>::Slice: AsBytes, { - move |input: I| { + move |input: &mut I| { match endian { Endianness::Big => be_i24, Endianness::Little => le_i24, @@ -1846,55 +1846,55 @@ where /// # Example /// /// ```rust -/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed}; +/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed}; /// # use winnow::prelude::*; /// # use winnow::error::Needed::Size; /// use winnow::binary::i32; /// /// let be_i32 = |s| { -/// i32(winnow::binary::Endianness::Big).parse_next(s) +/// i32(winnow::binary::Endianness::Big).parse_peek(s) /// }; /// /// assert_eq!(be_i32(&b"\x00\x03\x05\x07abcefg"[..]), Ok((&b"abcefg"[..], 0x00030507))); -/// assert_eq!(be_i32(&b"\x01"[..]), Err(ErrMode::Backtrack(Error::new(&[0x01][..], ErrorKind::Slice)))); +/// assert_eq!(be_i32(&b"\x01"[..]), Err(ErrMode::Backtrack(InputError::new(&[0x01][..], ErrorKind::Slice)))); /// /// let le_i32 = |s| { -/// i32(winnow::binary::Endianness::Little).parse_next(s) +/// i32(winnow::binary::Endianness::Little).parse_peek(s) /// }; /// /// assert_eq!(le_i32(&b"\x00\x03\x05\x07abcefg"[..]), Ok((&b"abcefg"[..], 0x07050300))); -/// assert_eq!(le_i32(&b"\x01"[..]), Err(ErrMode::Backtrack(Error::new(&[0x01][..], ErrorKind::Slice)))); +/// assert_eq!(le_i32(&b"\x01"[..]), Err(ErrMode::Backtrack(InputError::new(&[0x01][..], ErrorKind::Slice)))); /// ``` /// /// ```rust -/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed}; +/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed}; /// # use winnow::prelude::*; /// # use winnow::error::Needed::Size; /// # use winnow::Partial; /// use winnow::binary::i32; /// /// let be_i32 = |s| { -/// i32::<_, Error<_>>(winnow::binary::Endianness::Big).parse_next(s) +/// i32::<_, InputError<_>>(winnow::binary::Endianness::Big).parse_peek(s) /// }; /// /// assert_eq!(be_i32(Partial::new(&b"\x00\x03\x05\x07abcefg"[..])), Ok((Partial::new(&b"abcefg"[..]), 0x00030507))); /// assert_eq!(be_i32(Partial::new(&b"\x01"[..])), Err(ErrMode::Incomplete(Needed::new(3)))); /// /// let le_i32 = |s| { -/// i32::<_, Error<_>>(winnow::binary::Endianness::Little).parse_next(s) +/// i32::<_, InputError<_>>(winnow::binary::Endianness::Little).parse_peek(s) /// }; /// /// assert_eq!(le_i32(Partial::new(&b"\x00\x03\x05\x07abcefg"[..])), Ok((Partial::new(&b"abcefg"[..]), 0x07050300))); /// assert_eq!(le_i32(Partial::new(&b"\x01"[..])), Err(ErrMode::Incomplete(Needed::new(3)))); /// ``` #[inline(always)] -pub fn i32<I, E: ParseError<I>>(endian: Endianness) -> impl Parser<I, i32, E> +pub fn i32<I, E: ParserError<I>>(endian: Endianness) -> impl Parser<I, i32, E> where I: StreamIsPartial, I: Stream<Token = u8>, <I as Stream>::Slice: AsBytes, { - move |input: I| { + move |input: &mut I| { match endian { Endianness::Big => be_i32, Endianness::Little => le_i32, @@ -1918,55 +1918,55 @@ where /// # Example /// /// ```rust -/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed}; +/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed}; /// # use winnow::prelude::*; /// # use winnow::error::Needed::Size; /// use winnow::binary::i64; /// /// let be_i64 = |s| { -/// i64(winnow::binary::Endianness::Big).parse_next(s) +/// i64(winnow::binary::Endianness::Big).parse_peek(s) /// }; /// /// assert_eq!(be_i64(&b"\x00\x01\x02\x03\x04\x05\x06\x07abcefg"[..]), Ok((&b"abcefg"[..], 0x0001020304050607))); -/// assert_eq!(be_i64(&b"\x01"[..]), Err(ErrMode::Backtrack(Error::new(&[0x01][..], ErrorKind::Slice)))); +/// assert_eq!(be_i64(&b"\x01"[..]), Err(ErrMode::Backtrack(InputError::new(&[0x01][..], ErrorKind::Slice)))); /// /// let le_i64 = |s| { -/// i64(winnow::binary::Endianness::Little).parse_next(s) +/// i64(winnow::binary::Endianness::Little).parse_peek(s) /// }; /// /// assert_eq!(le_i64(&b"\x00\x01\x02\x03\x04\x05\x06\x07abcefg"[..]), Ok((&b"abcefg"[..], 0x0706050403020100))); -/// assert_eq!(le_i64(&b"\x01"[..]), Err(ErrMode::Backtrack(Error::new(&[0x01][..], ErrorKind::Slice)))); +/// assert_eq!(le_i64(&b"\x01"[..]), Err(ErrMode::Backtrack(InputError::new(&[0x01][..], ErrorKind::Slice)))); /// ``` /// /// ```rust -/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed}; +/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed}; /// # use winnow::prelude::*; /// # use winnow::error::Needed::Size; /// # use winnow::Partial; /// use winnow::binary::i64; /// /// let be_i64 = |s| { -/// i64::<_, Error<_>>(winnow::binary::Endianness::Big).parse_next(s) +/// i64::<_, InputError<_>>(winnow::binary::Endianness::Big).parse_peek(s) /// }; /// /// assert_eq!(be_i64(Partial::new(&b"\x00\x01\x02\x03\x04\x05\x06\x07abcefg"[..])), Ok((Partial::new(&b"abcefg"[..]), 0x0001020304050607))); /// assert_eq!(be_i64(Partial::new(&b"\x01"[..])), Err(ErrMode::Incomplete(Needed::new(7)))); /// /// let le_i64 = |s| { -/// i64::<_, Error<_>>(winnow::binary::Endianness::Little).parse_next(s) +/// i64::<_, InputError<_>>(winnow::binary::Endianness::Little).parse_peek(s) /// }; /// /// assert_eq!(le_i64(Partial::new(&b"\x00\x01\x02\x03\x04\x05\x06\x07abcefg"[..])), Ok((Partial::new(&b"abcefg"[..]), 0x0706050403020100))); /// assert_eq!(le_i64(Partial::new(&b"\x01"[..])), Err(ErrMode::Incomplete(Needed::new(7)))); /// ``` #[inline(always)] -pub fn i64<I, E: ParseError<I>>(endian: Endianness) -> impl Parser<I, i64, E> +pub fn i64<I, E: ParserError<I>>(endian: Endianness) -> impl Parser<I, i64, E> where I: StreamIsPartial, I: Stream<Token = u8>, <I as Stream>::Slice: AsBytes, { - move |input: I| { + move |input: &mut I| { match endian { Endianness::Big => be_i64, Endianness::Little => le_i64, @@ -1990,55 +1990,55 @@ where /// # Example /// /// ```rust -/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed}; +/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed}; /// # use winnow::prelude::*; /// # use winnow::error::Needed::Size; /// use winnow::binary::i128; /// /// let be_i128 = |s| { -/// i128(winnow::binary::Endianness::Big).parse_next(s) +/// i128(winnow::binary::Endianness::Big).parse_peek(s) /// }; /// /// assert_eq!(be_i128(&b"\x00\x01\x02\x03\x04\x05\x06\x07\x00\x01\x02\x03\x04\x05\x06\x07abcefg"[..]), Ok((&b"abcefg"[..], 0x00010203040506070001020304050607))); -/// assert_eq!(be_i128(&b"\x01"[..]), Err(ErrMode::Backtrack(Error::new(&[0x01][..], ErrorKind::Slice)))); +/// assert_eq!(be_i128(&b"\x01"[..]), Err(ErrMode::Backtrack(InputError::new(&[0x01][..], ErrorKind::Slice)))); /// /// let le_i128 = |s| { -/// i128(winnow::binary::Endianness::Little).parse_next(s) +/// i128(winnow::binary::Endianness::Little).parse_peek(s) /// }; /// /// assert_eq!(le_i128(&b"\x00\x01\x02\x03\x04\x05\x06\x07\x00\x01\x02\x03\x04\x05\x06\x07abcefg"[..]), Ok((&b"abcefg"[..], 0x07060504030201000706050403020100))); -/// assert_eq!(le_i128(&b"\x01"[..]), Err(ErrMode::Backtrack(Error::new(&[0x01][..], ErrorKind::Slice)))); +/// assert_eq!(le_i128(&b"\x01"[..]), Err(ErrMode::Backtrack(InputError::new(&[0x01][..], ErrorKind::Slice)))); /// ``` /// /// ```rust -/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed}; +/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed}; /// # use winnow::prelude::*; /// # use winnow::error::Needed::Size; /// # use winnow::Partial; /// use winnow::binary::i128; /// /// let be_i128 = |s| { -/// i128::<_, Error<_>>(winnow::binary::Endianness::Big).parse_next(s) +/// i128::<_, InputError<_>>(winnow::binary::Endianness::Big).parse_peek(s) /// }; /// /// assert_eq!(be_i128(Partial::new(&b"\x00\x01\x02\x03\x04\x05\x06\x07\x00\x01\x02\x03\x04\x05\x06\x07abcefg"[..])), Ok((Partial::new(&b"abcefg"[..]), 0x00010203040506070001020304050607))); /// assert_eq!(be_i128(Partial::new(&b"\x01"[..])), Err(ErrMode::Incomplete(Needed::new(15)))); /// /// let le_i128 = |s| { -/// i128::<_, Error<_>>(winnow::binary::Endianness::Little).parse_next(s) +/// i128::<_, InputError<_>>(winnow::binary::Endianness::Little).parse_peek(s) /// }; /// /// assert_eq!(le_i128(Partial::new(&b"\x00\x01\x02\x03\x04\x05\x06\x07\x00\x01\x02\x03\x04\x05\x06\x07abcefg"[..])), Ok((Partial::new(&b"abcefg"[..]), 0x07060504030201000706050403020100))); /// assert_eq!(le_i128(Partial::new(&b"\x01"[..])), Err(ErrMode::Incomplete(Needed::new(15)))); /// ``` #[inline(always)] -pub fn i128<I, E: ParseError<I>>(endian: Endianness) -> impl Parser<I, i128, E> +pub fn i128<I, E: ParserError<I>>(endian: Endianness) -> impl Parser<I, i128, E> where I: StreamIsPartial, I: Stream<Token = u8>, <I as Stream>::Slice: AsBytes, { - move |input: I| { + move |input: &mut I| { match endian { Endianness::Big => be_i128, Endianness::Little => le_i128, @@ -2059,42 +2059,42 @@ where /// # Example /// /// ```rust -/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed}; +/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed}; /// # use winnow::prelude::*; /// # use winnow::prelude::*; /// # use winnow::error::Needed::Size; /// use winnow::binary::be_f32; /// /// fn parser(s: &[u8]) -> IResult<&[u8], f32> { -/// be_f32.parse_next(s) +/// be_f32.parse_peek(s) /// } /// /// assert_eq!(parser(&[0x41, 0x48, 0x00, 0x00][..]), Ok((&b""[..], 12.5))); -/// assert_eq!(parser(&b"abc"[..]), Err(ErrMode::Backtrack(Error::new(&b"abc"[..], ErrorKind::Slice)))); +/// assert_eq!(parser(&b"abc"[..]), Err(ErrMode::Backtrack(InputError::new(&b"abc"[..], ErrorKind::Slice)))); /// ``` /// /// ```rust -/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed}; +/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed}; /// # use winnow::prelude::*; /// # use winnow::Partial; /// use winnow::binary::be_f32; /// /// fn parser(s: Partial<&[u8]>) -> IResult<Partial<&[u8]>, f32> { -/// be_f32.parse_next(s) +/// be_f32.parse_peek(s) /// } /// /// assert_eq!(parser(Partial::new(&[0x40, 0x29, 0x00, 0x00][..])), Ok((Partial::new(&b""[..]), 2.640625))); /// assert_eq!(parser(Partial::new(&[0x01][..])), Err(ErrMode::Incomplete(Needed::new(3)))); /// ``` #[inline(always)] -pub fn be_f32<I, E: ParseError<I>>(input: I) -> IResult<I, f32, E> +pub fn be_f32<I, E: ParserError<I>>(input: &mut I) -> PResult<f32, E> where I: StreamIsPartial, I: Stream<Token = u8>, <I as Stream>::Slice: AsBytes, { - trace("be_f32", move |input: I| { - be_uint::<_, u32, _>(input, 4).map(|(i, n)| (i, f32::from_bits(n))) + trace("be_f32", move |input: &mut I| { + be_uint::<_, u32, _>(input, 4).map(f32::from_bits) }) .parse_next(input) } @@ -2108,41 +2108,41 @@ where /// # Example /// /// ```rust -/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed}; +/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed}; /// # use winnow::prelude::*; /// # use winnow::error::Needed::Size; /// use winnow::binary::be_f64; /// /// fn parser(s: &[u8]) -> IResult<&[u8], f64> { -/// be_f64.parse_next(s) +/// be_f64.parse_peek(s) /// } /// /// assert_eq!(parser(&[0x40, 0x29, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00][..]), Ok((&b""[..], 12.5))); -/// assert_eq!(parser(&b"abc"[..]), Err(ErrMode::Backtrack(Error::new(&b"abc"[..], ErrorKind::Slice)))); +/// assert_eq!(parser(&b"abc"[..]), Err(ErrMode::Backtrack(InputError::new(&b"abc"[..], ErrorKind::Slice)))); /// ``` /// /// ```rust -/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed}; +/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed}; /// # use winnow::prelude::*; /// # use winnow::Partial; /// use winnow::binary::be_f64; /// /// fn parser(s: Partial<&[u8]>) -> IResult<Partial<&[u8]>, f64> { -/// be_f64::<_, Error<_>>.parse_next(s) +/// be_f64::<_, InputError<_>>.parse_peek(s) /// } /// /// assert_eq!(parser(Partial::new(&[0x40, 0x29, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00][..])), Ok((Partial::new(&b""[..]), 12.5))); /// assert_eq!(parser(Partial::new(&[0x01][..])), Err(ErrMode::Incomplete(Needed::new(7)))); /// ``` #[inline(always)] -pub fn be_f64<I, E: ParseError<I>>(input: I) -> IResult<I, f64, E> +pub fn be_f64<I, E: ParserError<I>>(input: &mut I) -> PResult<f64, E> where I: StreamIsPartial, I: Stream<Token = u8>, <I as Stream>::Slice: AsBytes, { - trace("be_f64", move |input: I| { - be_uint::<_, u64, _>(input, 8).map(|(i, n)| (i, f64::from_bits(n))) + trace("be_f64", move |input: &mut I| { + be_uint::<_, u64, _>(input, 8).map(f64::from_bits) }) .parse_next(input) } @@ -2156,41 +2156,41 @@ where /// # Example /// /// ```rust -/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed}; +/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed}; /// # use winnow::prelude::*; /// # use winnow::error::Needed::Size; /// use winnow::binary::le_f32; /// /// fn parser(s: &[u8]) -> IResult<&[u8], f32> { -/// le_f32.parse_next(s) +/// le_f32.parse_peek(s) /// } /// /// assert_eq!(parser(&[0x00, 0x00, 0x48, 0x41][..]), Ok((&b""[..], 12.5))); -/// assert_eq!(parser(&b"abc"[..]), Err(ErrMode::Backtrack(Error::new(&b"abc"[..], ErrorKind::Slice)))); +/// assert_eq!(parser(&b"abc"[..]), Err(ErrMode::Backtrack(InputError::new(&b"abc"[..], ErrorKind::Slice)))); /// ``` /// /// ```rust -/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed}; +/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed}; /// # use winnow::prelude::*; /// # use winnow::Partial; /// use winnow::binary::le_f32; /// /// fn parser(s: Partial<&[u8]>) -> IResult<Partial<&[u8]>, f32> { -/// le_f32::<_, Error<_>>.parse_next(s) +/// le_f32::<_, InputError<_>>.parse_peek(s) /// } /// /// assert_eq!(parser(Partial::new(&[0x00, 0x00, 0x48, 0x41][..])), Ok((Partial::new(&b""[..]), 12.5))); /// assert_eq!(parser(Partial::new(&[0x01][..])), Err(ErrMode::Incomplete(Needed::new(3)))); /// ``` #[inline(always)] -pub fn le_f32<I, E: ParseError<I>>(input: I) -> IResult<I, f32, E> +pub fn le_f32<I, E: ParserError<I>>(input: &mut I) -> PResult<f32, E> where I: StreamIsPartial, I: Stream<Token = u8>, <I as Stream>::Slice: AsBytes, { - trace("le_f32", move |input: I| { - le_uint::<_, u32, _>(input, 4).map(|(i, n)| (i, f32::from_bits(n))) + trace("le_f32", move |input: &mut I| { + le_uint::<_, u32, _>(input, 4).map(f32::from_bits) }) .parse_next(input) } @@ -2204,41 +2204,41 @@ where /// # Example /// /// ```rust -/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed}; +/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed}; /// # use winnow::prelude::*; /// # use winnow::error::Needed::Size; /// use winnow::binary::le_f64; /// /// fn parser(s: &[u8]) -> IResult<&[u8], f64> { -/// le_f64.parse_next(s) +/// le_f64.parse_peek(s) /// } /// /// assert_eq!(parser(&[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x29, 0x40][..]), Ok((&b""[..], 12.5))); -/// assert_eq!(parser(&b"abc"[..]), Err(ErrMode::Backtrack(Error::new(&b"abc"[..], ErrorKind::Slice)))); +/// assert_eq!(parser(&b"abc"[..]), Err(ErrMode::Backtrack(InputError::new(&b"abc"[..], ErrorKind::Slice)))); /// ``` /// /// ```rust -/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed}; +/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed}; /// # use winnow::prelude::*; /// # use winnow::Partial; /// use winnow::binary::le_f64; /// /// fn parser(s: Partial<&[u8]>) -> IResult<Partial<&[u8]>, f64> { -/// le_f64::<_, Error<_>>.parse_next(s) +/// le_f64::<_, InputError<_>>.parse_peek(s) /// } /// /// assert_eq!(parser(Partial::new(&[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x48, 0x41][..])), Ok((Partial::new(&b""[..]), 3145728.0))); /// assert_eq!(parser(Partial::new(&[0x01][..])), Err(ErrMode::Incomplete(Needed::new(7)))); /// ``` #[inline(always)] -pub fn le_f64<I, E: ParseError<I>>(input: I) -> IResult<I, f64, E> +pub fn le_f64<I, E: ParserError<I>>(input: &mut I) -> PResult<f64, E> where I: StreamIsPartial, I: Stream<Token = u8>, <I as Stream>::Slice: AsBytes, { - trace("be_f64", move |input: I| { - le_uint::<_, u64, _>(input, 8).map(|(i, n)| (i, f64::from_bits(n))) + trace("be_f64", move |input: &mut I| { + le_uint::<_, u64, _>(input, 8).map(f64::from_bits) }) .parse_next(input) } @@ -2255,55 +2255,55 @@ where /// # Example /// /// ```rust -/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed}; +/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed}; /// # use winnow::prelude::*; /// # use winnow::error::Needed::Size; /// use winnow::binary::f32; /// /// let be_f32 = |s| { -/// f32(winnow::binary::Endianness::Big).parse_next(s) +/// f32(winnow::binary::Endianness::Big).parse_peek(s) /// }; /// /// assert_eq!(be_f32(&[0x41, 0x48, 0x00, 0x00][..]), Ok((&b""[..], 12.5))); -/// assert_eq!(be_f32(&b"abc"[..]), Err(ErrMode::Backtrack(Error::new(&b"abc"[..], ErrorKind::Slice)))); +/// assert_eq!(be_f32(&b"abc"[..]), Err(ErrMode::Backtrack(InputError::new(&b"abc"[..], ErrorKind::Slice)))); /// /// let le_f32 = |s| { -/// f32(winnow::binary::Endianness::Little).parse_next(s) +/// f32(winnow::binary::Endianness::Little).parse_peek(s) /// }; /// /// assert_eq!(le_f32(&[0x00, 0x00, 0x48, 0x41][..]), Ok((&b""[..], 12.5))); -/// assert_eq!(le_f32(&b"abc"[..]), Err(ErrMode::Backtrack(Error::new(&b"abc"[..], ErrorKind::Slice)))); +/// assert_eq!(le_f32(&b"abc"[..]), Err(ErrMode::Backtrack(InputError::new(&b"abc"[..], ErrorKind::Slice)))); /// ``` /// /// ```rust -/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed}; +/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed}; /// # use winnow::prelude::*; /// # use winnow::error::Needed::Size; /// # use winnow::Partial; /// use winnow::binary::f32; /// /// let be_f32 = |s| { -/// f32::<_, Error<_>>(winnow::binary::Endianness::Big).parse_next(s) +/// f32::<_, InputError<_>>(winnow::binary::Endianness::Big).parse_peek(s) /// }; /// /// assert_eq!(be_f32(Partial::new(&[0x41, 0x48, 0x00, 0x00][..])), Ok((Partial::new(&b""[..]), 12.5))); /// assert_eq!(be_f32(Partial::new(&b"abc"[..])), Err(ErrMode::Incomplete(Needed::new(1)))); /// /// let le_f32 = |s| { -/// f32::<_, Error<_>>(winnow::binary::Endianness::Little).parse_next(s) +/// f32::<_, InputError<_>>(winnow::binary::Endianness::Little).parse_peek(s) /// }; /// /// assert_eq!(le_f32(Partial::new(&[0x00, 0x00, 0x48, 0x41][..])), Ok((Partial::new(&b""[..]), 12.5))); /// assert_eq!(le_f32(Partial::new(&b"abc"[..])), Err(ErrMode::Incomplete(Needed::new(1)))); /// ``` #[inline(always)] -pub fn f32<I, E: ParseError<I>>(endian: Endianness) -> impl Parser<I, f32, E> +pub fn f32<I, E: ParserError<I>>(endian: Endianness) -> impl Parser<I, f32, E> where I: StreamIsPartial, I: Stream<Token = u8>, <I as Stream>::Slice: AsBytes, { - move |input: I| { + move |input: &mut I| { match endian { Endianness::Big => be_f32, Endianness::Little => le_f32, @@ -2327,55 +2327,55 @@ where /// # Example /// /// ```rust -/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed}; +/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed}; /// # use winnow::prelude::*; /// # use winnow::error::Needed::Size; /// use winnow::binary::f64; /// /// let be_f64 = |s| { -/// f64(winnow::binary::Endianness::Big).parse_next(s) +/// f64(winnow::binary::Endianness::Big).parse_peek(s) /// }; /// /// assert_eq!(be_f64(&[0x40, 0x29, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00][..]), Ok((&b""[..], 12.5))); -/// assert_eq!(be_f64(&b"abc"[..]), Err(ErrMode::Backtrack(Error::new(&b"abc"[..], ErrorKind::Slice)))); +/// assert_eq!(be_f64(&b"abc"[..]), Err(ErrMode::Backtrack(InputError::new(&b"abc"[..], ErrorKind::Slice)))); /// /// let le_f64 = |s| { -/// f64(winnow::binary::Endianness::Little).parse_next(s) +/// f64(winnow::binary::Endianness::Little).parse_peek(s) /// }; /// /// assert_eq!(le_f64(&[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x29, 0x40][..]), Ok((&b""[..], 12.5))); -/// assert_eq!(le_f64(&b"abc"[..]), Err(ErrMode::Backtrack(Error::new(&b"abc"[..], ErrorKind::Slice)))); +/// assert_eq!(le_f64(&b"abc"[..]), Err(ErrMode::Backtrack(InputError::new(&b"abc"[..], ErrorKind::Slice)))); /// ``` /// /// ```rust -/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed}; +/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed}; /// # use winnow::prelude::*; /// # use winnow::error::Needed::Size; /// # use winnow::Partial; /// use winnow::binary::f64; /// /// let be_f64 = |s| { -/// f64::<_, Error<_>>(winnow::binary::Endianness::Big).parse_next(s) +/// f64::<_, InputError<_>>(winnow::binary::Endianness::Big).parse_peek(s) /// }; /// /// assert_eq!(be_f64(Partial::new(&[0x40, 0x29, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00][..])), Ok((Partial::new(&b""[..]), 12.5))); /// assert_eq!(be_f64(Partial::new(&b"abc"[..])), Err(ErrMode::Incomplete(Needed::new(5)))); /// /// let le_f64 = |s| { -/// f64::<_, Error<_>>(winnow::binary::Endianness::Little).parse_next(s) +/// f64::<_, InputError<_>>(winnow::binary::Endianness::Little).parse_peek(s) /// }; /// /// assert_eq!(le_f64(Partial::new(&[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x29, 0x40][..])), Ok((Partial::new(&b""[..]), 12.5))); /// assert_eq!(le_f64(Partial::new(&b"abc"[..])), Err(ErrMode::Incomplete(Needed::new(5)))); /// ``` #[inline(always)] -pub fn f64<I, E: ParseError<I>>(endian: Endianness) -> impl Parser<I, f64, E> +pub fn f64<I, E: ParserError<I>>(endian: Endianness) -> impl Parser<I, f64, E> where I: StreamIsPartial, I: Stream<Token = u8>, <I as Stream>::Slice: AsBytes, { - move |input: I| { + move |input: &mut I| { match endian { Endianness::Big => be_f64, Endianness::Little => le_f64, @@ -2414,7 +2414,7 @@ where /// } /// /// fn parser(s: Stream<'_>) -> IResult<Stream<'_>, &[u8]> { -/// length_data(be_u16).parse_next(s) +/// length_data(be_u16).parse_peek(s) /// } /// /// assert_eq!(parser(stream(b"\x00\x03abcefg")), Ok((stream(&b"efg"[..]), &b"abc"[..]))); @@ -2426,10 +2426,10 @@ where I: Stream, N: ToUsize, F: Parser<I, N, E>, - E: ParseError<I>, + E: ParserError<I>, { - trace("length_data", move |i: I| { - let (i, length) = f.parse_next(i)?; + trace("length_data", move |i: &mut I| { + let length = f.parse_next(i)?; crate::token::take(length).parse_next(i) }) @@ -2452,7 +2452,7 @@ where /// # Example /// /// ```rust -/// # use winnow::{error::ErrMode, error::{Error, ErrorKind}, error::Needed, stream::{Partial, StreamIsPartial}}; +/// # use winnow::{error::ErrMode, error::{InputError, ErrorKind}, error::Needed, stream::{Partial, StreamIsPartial}}; /// # use winnow::prelude::*; /// use winnow::Bytes; /// use winnow::binary::be_u16; @@ -2472,28 +2472,28 @@ where /// } /// /// fn parser(s: Stream<'_>) -> IResult<Stream<'_>, &[u8]> { -/// length_value(be_u16, "abc").parse_next(s) +/// length_value(be_u16, "abc").parse_peek(s) /// } /// /// assert_eq!(parser(stream(b"\x00\x03abcefg")), Ok((stream(&b"efg"[..]), &b"abc"[..]))); -/// assert_eq!(parser(stream(b"\x00\x03123123")), Err(ErrMode::Backtrack(Error::new(complete_stream(&b"123"[..]), ErrorKind::Tag)))); +/// assert_eq!(parser(stream(b"\x00\x03123123")), Err(ErrMode::Backtrack(InputError::new(complete_stream(&b"123"[..]), ErrorKind::Tag)))); /// assert_eq!(parser(stream(b"\x00\x03a")), Err(ErrMode::Incomplete(Needed::new(2)))); /// ``` pub fn length_value<I, O, N, E, F, G>(mut f: F, mut g: G) -> impl Parser<I, O, E> where I: StreamIsPartial, - I: Stream + UpdateSlice, + I: Stream + UpdateSlice + Clone, N: ToUsize, F: Parser<I, N, E>, G: Parser<I, O, E>, - E: ParseError<I>, + E: ParserError<I>, { - trace("length_value", move |i: I| { - let (i, data) = length_data(f.by_ref()).parse_next(i)?; + trace("length_value", move |i: &mut I| { + let data = length_data(f.by_ref()).parse_next(i)?; let mut data = I::update_slice(i.clone(), data); let _ = data.complete(); - let (_, o) = g.by_ref().complete_err().parse_next(data)?; - Ok((i, o)) + let o = g.by_ref().complete_err().parse_next(&mut data)?; + Ok(o) }) } @@ -2509,7 +2509,7 @@ where /// ```rust /// # #[cfg(feature = "std")] { /// # use winnow::prelude::*; -/// # use winnow::{error::ErrMode, error::{Error, ErrorKind}, error::Needed}; +/// # use winnow::{error::ErrMode, error::{InputError, ErrorKind}, error::Needed}; /// # use winnow::prelude::*; /// use winnow::Bytes; /// use winnow::binary::u8; @@ -2526,11 +2526,11 @@ where /// length_count(u8.map(|i| { /// println!("got number: {}", i); /// i -/// }), "abc").parse_next(s) +/// }), "abc").parse_peek(s) /// } /// /// assert_eq!(parser(stream(b"\x02abcabcabc")), Ok((stream(b"abc"), vec![&b"abc"[..], &b"abc"[..]]))); -/// assert_eq!(parser(stream(b"\x03123123123")), Err(ErrMode::Backtrack(Error::new(stream(b"123123123"), ErrorKind::Tag)))); +/// assert_eq!(parser(stream(b"\x03123123123")), Err(ErrMode::Backtrack(InputError::new(stream(b"123123123"), ErrorKind::Tag)))); /// # } /// ``` pub fn length_count<I, O, C, N, E, F, G>(mut f: F, mut g: G) -> impl Parser<I, C, E> @@ -2540,10 +2540,10 @@ where C: Accumulate<O>, F: Parser<I, N, E>, G: Parser<I, O, E>, - E: ParseError<I>, + E: ParserError<I>, { - trace("length_count", move |i: I| { - let (i, n) = f.parse_next(i)?; + trace("length_count", move |i: &mut I| { + let n = f.parse_next(i)?; let n = n.to_usize(); repeat(n, g.by_ref()).parse_next(i) }) diff --git a/vendor/winnow/src/binary/tests.rs b/vendor/winnow/src/binary/tests.rs index 4307d88fe..5d92055ac 100644 --- a/vendor/winnow/src/binary/tests.rs +++ b/vendor/winnow/src/binary/tests.rs @@ -1,70 +1,96 @@ use super::*; +use crate::unpeek; +use crate::IResult; mod complete { use super::*; - use crate::error::Error; + use crate::error::InputError; macro_rules! assert_parse( ($left: expr, $right: expr) => { - let res: $crate::IResult<_, _, Error<_>> = $left; + let res: $crate::IResult<_, _, InputError<_>> = $left; assert_eq!(res, $right); }; ); #[test] fn i8_tests() { - assert_parse!(i8(&[0x00][..]), Ok((&b""[..], 0))); - assert_parse!(i8(&[0x7f][..]), Ok((&b""[..], 127))); - assert_parse!(i8(&[0xff][..]), Ok((&b""[..], -1))); - assert_parse!(i8(&[0x80][..]), Ok((&b""[..], -128))); + assert_parse!(i8.parse_peek(&[0x00][..]), Ok((&b""[..], 0))); + assert_parse!(i8.parse_peek(&[0x7f][..]), Ok((&b""[..], 127))); + assert_parse!(i8.parse_peek(&[0xff][..]), Ok((&b""[..], -1))); + assert_parse!(i8.parse_peek(&[0x80][..]), Ok((&b""[..], -128))); } #[test] fn be_i8_tests() { - assert_parse!(be_i8(&[0x00][..]), Ok((&b""[..], 0))); - assert_parse!(be_i8(&[0x7f][..]), Ok((&b""[..], 127))); - assert_parse!(be_i8(&[0xff][..]), Ok((&b""[..], -1))); - assert_parse!(be_i8(&[0x80][..]), Ok((&b""[..], -128))); + assert_parse!(be_i8.parse_peek(&[0x00][..]), Ok((&b""[..], 0))); + assert_parse!(be_i8.parse_peek(&[0x7f][..]), Ok((&b""[..], 127))); + assert_parse!(be_i8.parse_peek(&[0xff][..]), Ok((&b""[..], -1))); + assert_parse!(be_i8.parse_peek(&[0x80][..]), Ok((&b""[..], -128))); } #[test] fn be_i16_tests() { - assert_parse!(be_i16(&[0x00, 0x00][..]), Ok((&b""[..], 0))); - assert_parse!(be_i16(&[0x7f, 0xff][..]), Ok((&b""[..], 32_767_i16))); - assert_parse!(be_i16(&[0xff, 0xff][..]), Ok((&b""[..], -1))); - assert_parse!(be_i16(&[0x80, 0x00][..]), Ok((&b""[..], -32_768_i16))); + assert_parse!(be_i16.parse_peek(&[0x00, 0x00][..]), Ok((&b""[..], 0))); + assert_parse!( + be_i16.parse_peek(&[0x7f, 0xff][..]), + Ok((&b""[..], 32_767_i16)) + ); + assert_parse!(be_i16.parse_peek(&[0xff, 0xff][..]), Ok((&b""[..], -1))); + assert_parse!( + be_i16.parse_peek(&[0x80, 0x00][..]), + Ok((&b""[..], -32_768_i16)) + ); } #[test] fn be_u24_tests() { - assert_parse!(be_u24(&[0x00, 0x00, 0x00][..]), Ok((&b""[..], 0))); - assert_parse!(be_u24(&[0x00, 0xFF, 0xFF][..]), Ok((&b""[..], 65_535_u32))); assert_parse!( - be_u24(&[0x12, 0x34, 0x56][..]), + be_u24.parse_peek(&[0x00, 0x00, 0x00][..]), + Ok((&b""[..], 0)) + ); + assert_parse!( + be_u24.parse_peek(&[0x00, 0xFF, 0xFF][..]), + Ok((&b""[..], 65_535_u32)) + ); + assert_parse!( + be_u24.parse_peek(&[0x12, 0x34, 0x56][..]), Ok((&b""[..], 1_193_046_u32)) ); } #[test] fn be_i24_tests() { - assert_parse!(be_i24(&[0xFF, 0xFF, 0xFF][..]), Ok((&b""[..], -1_i32))); - assert_parse!(be_i24(&[0xFF, 0x00, 0x00][..]), Ok((&b""[..], -65_536_i32))); assert_parse!( - be_i24(&[0xED, 0xCB, 0xAA][..]), + be_i24.parse_peek(&[0xFF, 0xFF, 0xFF][..]), + Ok((&b""[..], -1_i32)) + ); + assert_parse!( + be_i24.parse_peek(&[0xFF, 0x00, 0x00][..]), + Ok((&b""[..], -65_536_i32)) + ); + assert_parse!( + be_i24.parse_peek(&[0xED, 0xCB, 0xAA][..]), Ok((&b""[..], -1_193_046_i32)) ); } #[test] fn be_i32_tests() { - assert_parse!(be_i32(&[0x00, 0x00, 0x00, 0x00][..]), Ok((&b""[..], 0))); assert_parse!( - be_i32(&[0x7f, 0xff, 0xff, 0xff][..]), + be_i32.parse_peek(&[0x00, 0x00, 0x00, 0x00][..]), + Ok((&b""[..], 0)) + ); + assert_parse!( + be_i32.parse_peek(&[0x7f, 0xff, 0xff, 0xff][..]), Ok((&b""[..], 2_147_483_647_i32)) ); - assert_parse!(be_i32(&[0xff, 0xff, 0xff, 0xff][..]), Ok((&b""[..], -1))); assert_parse!( - be_i32(&[0x80, 0x00, 0x00, 0x00][..]), + be_i32.parse_peek(&[0xff, 0xff, 0xff, 0xff][..]), + Ok((&b""[..], -1)) + ); + assert_parse!( + be_i32.parse_peek(&[0x80, 0x00, 0x00, 0x00][..]), Ok((&b""[..], -2_147_483_648_i32)) ); } @@ -72,19 +98,19 @@ mod complete { #[test] fn be_i64_tests() { assert_parse!( - be_i64(&[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00][..]), + be_i64.parse_peek(&[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00][..]), Ok((&b""[..], 0)) ); assert_parse!( - be_i64(&[0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff][..]), + be_i64.parse_peek(&[0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff][..]), Ok((&b""[..], 9_223_372_036_854_775_807_i64)) ); assert_parse!( - be_i64(&[0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff][..]), + be_i64.parse_peek(&[0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff][..]), Ok((&b""[..], -1)) ); assert_parse!( - be_i64(&[0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00][..]), + be_i64.parse_peek(&[0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00][..]), Ok((&b""[..], -9_223_372_036_854_775_808_i64)) ); } @@ -92,7 +118,7 @@ mod complete { #[test] fn be_i128_tests() { assert_parse!( - be_i128( + be_i128.parse_peek( &[ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 @@ -101,7 +127,7 @@ mod complete { Ok((&b""[..], 0)) ); assert_parse!( - be_i128( + be_i128.parse_peek( &[ 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff @@ -113,7 +139,7 @@ mod complete { )) ); assert_parse!( - be_i128( + be_i128.parse_peek( &[ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff @@ -122,7 +148,7 @@ mod complete { Ok((&b""[..], -1)) ); assert_parse!( - be_i128( + be_i128.parse_peek( &[ 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 @@ -137,50 +163,74 @@ mod complete { #[test] fn le_i8_tests() { - assert_parse!(le_i8(&[0x00][..]), Ok((&b""[..], 0))); - assert_parse!(le_i8(&[0x7f][..]), Ok((&b""[..], 127))); - assert_parse!(le_i8(&[0xff][..]), Ok((&b""[..], -1))); - assert_parse!(le_i8(&[0x80][..]), Ok((&b""[..], -128))); + assert_parse!(le_i8.parse_peek(&[0x00][..]), Ok((&b""[..], 0))); + assert_parse!(le_i8.parse_peek(&[0x7f][..]), Ok((&b""[..], 127))); + assert_parse!(le_i8.parse_peek(&[0xff][..]), Ok((&b""[..], -1))); + assert_parse!(le_i8.parse_peek(&[0x80][..]), Ok((&b""[..], -128))); } #[test] fn le_i16_tests() { - assert_parse!(le_i16(&[0x00, 0x00][..]), Ok((&b""[..], 0))); - assert_parse!(le_i16(&[0xff, 0x7f][..]), Ok((&b""[..], 32_767_i16))); - assert_parse!(le_i16(&[0xff, 0xff][..]), Ok((&b""[..], -1))); - assert_parse!(le_i16(&[0x00, 0x80][..]), Ok((&b""[..], -32_768_i16))); + assert_parse!(le_i16.parse_peek(&[0x00, 0x00][..]), Ok((&b""[..], 0))); + assert_parse!( + le_i16.parse_peek(&[0xff, 0x7f][..]), + Ok((&b""[..], 32_767_i16)) + ); + assert_parse!(le_i16.parse_peek(&[0xff, 0xff][..]), Ok((&b""[..], -1))); + assert_parse!( + le_i16.parse_peek(&[0x00, 0x80][..]), + Ok((&b""[..], -32_768_i16)) + ); } #[test] fn le_u24_tests() { - assert_parse!(le_u24(&[0x00, 0x00, 0x00][..]), Ok((&b""[..], 0))); - assert_parse!(le_u24(&[0xFF, 0xFF, 0x00][..]), Ok((&b""[..], 65_535_u32))); assert_parse!( - le_u24(&[0x56, 0x34, 0x12][..]), + le_u24.parse_peek(&[0x00, 0x00, 0x00][..]), + Ok((&b""[..], 0)) + ); + assert_parse!( + le_u24.parse_peek(&[0xFF, 0xFF, 0x00][..]), + Ok((&b""[..], 65_535_u32)) + ); + assert_parse!( + le_u24.parse_peek(&[0x56, 0x34, 0x12][..]), Ok((&b""[..], 1_193_046_u32)) ); } #[test] fn le_i24_tests() { - assert_parse!(le_i24(&[0xFF, 0xFF, 0xFF][..]), Ok((&b""[..], -1_i32))); - assert_parse!(le_i24(&[0x00, 0x00, 0xFF][..]), Ok((&b""[..], -65_536_i32))); assert_parse!( - le_i24(&[0xAA, 0xCB, 0xED][..]), + le_i24.parse_peek(&[0xFF, 0xFF, 0xFF][..]), + Ok((&b""[..], -1_i32)) + ); + assert_parse!( + le_i24.parse_peek(&[0x00, 0x00, 0xFF][..]), + Ok((&b""[..], -65_536_i32)) + ); + assert_parse!( + le_i24.parse_peek(&[0xAA, 0xCB, 0xED][..]), Ok((&b""[..], -1_193_046_i32)) ); } #[test] fn le_i32_tests() { - assert_parse!(le_i32(&[0x00, 0x00, 0x00, 0x00][..]), Ok((&b""[..], 0))); assert_parse!( - le_i32(&[0xff, 0xff, 0xff, 0x7f][..]), + le_i32.parse_peek(&[0x00, 0x00, 0x00, 0x00][..]), + Ok((&b""[..], 0)) + ); + assert_parse!( + le_i32.parse_peek(&[0xff, 0xff, 0xff, 0x7f][..]), Ok((&b""[..], 2_147_483_647_i32)) ); - assert_parse!(le_i32(&[0xff, 0xff, 0xff, 0xff][..]), Ok((&b""[..], -1))); assert_parse!( - le_i32(&[0x00, 0x00, 0x00, 0x80][..]), + le_i32.parse_peek(&[0xff, 0xff, 0xff, 0xff][..]), + Ok((&b""[..], -1)) + ); + assert_parse!( + le_i32.parse_peek(&[0x00, 0x00, 0x00, 0x80][..]), Ok((&b""[..], -2_147_483_648_i32)) ); } @@ -188,19 +238,19 @@ mod complete { #[test] fn le_i64_tests() { assert_parse!( - le_i64(&[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00][..]), + le_i64.parse_peek(&[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00][..]), Ok((&b""[..], 0)) ); assert_parse!( - le_i64(&[0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f][..]), + le_i64.parse_peek(&[0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f][..]), Ok((&b""[..], 9_223_372_036_854_775_807_i64)) ); assert_parse!( - le_i64(&[0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff][..]), + le_i64.parse_peek(&[0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff][..]), Ok((&b""[..], -1)) ); assert_parse!( - le_i64(&[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80][..]), + le_i64.parse_peek(&[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80][..]), Ok((&b""[..], -9_223_372_036_854_775_808_i64)) ); } @@ -208,7 +258,7 @@ mod complete { #[test] fn le_i128_tests() { assert_parse!( - le_i128( + le_i128.parse_peek( &[ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 @@ -217,7 +267,7 @@ mod complete { Ok((&b""[..], 0)) ); assert_parse!( - le_i128( + le_i128.parse_peek( &[ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f @@ -229,7 +279,7 @@ mod complete { )) ); assert_parse!( - le_i128( + le_i128.parse_peek( &[ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff @@ -238,7 +288,7 @@ mod complete { Ok((&b""[..], -1)) ); assert_parse!( - le_i128( + le_i128.parse_peek( &[ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80 @@ -253,9 +303,12 @@ mod complete { #[test] fn be_f32_tests() { - assert_parse!(be_f32(&[0x00, 0x00, 0x00, 0x00][..]), Ok((&b""[..], 0_f32))); assert_parse!( - be_f32(&[0x4d, 0x31, 0x1f, 0xd8][..]), + be_f32.parse_peek(&[0x00, 0x00, 0x00, 0x00][..]), + Ok((&b""[..], 0_f32)) + ); + assert_parse!( + be_f32.parse_peek(&[0x4d, 0x31, 0x1f, 0xd8][..]), Ok((&b""[..], 185_728_380_f32)) ); } @@ -263,20 +316,23 @@ mod complete { #[test] fn be_f64_tests() { assert_parse!( - be_f64(&[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00][..]), + be_f64.parse_peek(&[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00][..]), Ok((&b""[..], 0_f64)) ); assert_parse!( - be_f64(&[0x41, 0xa6, 0x23, 0xfb, 0x10, 0x00, 0x00, 0x00][..]), + be_f64.parse_peek(&[0x41, 0xa6, 0x23, 0xfb, 0x10, 0x00, 0x00, 0x00][..]), Ok((&b""[..], 185_728_392_f64)) ); } #[test] fn le_f32_tests() { - assert_parse!(le_f32(&[0x00, 0x00, 0x00, 0x00][..]), Ok((&b""[..], 0_f32))); assert_parse!( - le_f32(&[0xd8, 0x1f, 0x31, 0x4d][..]), + le_f32.parse_peek(&[0x00, 0x00, 0x00, 0x00][..]), + Ok((&b""[..], 0_f32)) + ); + assert_parse!( + le_f32.parse_peek(&[0xd8, 0x1f, 0x31, 0x4d][..]), Ok((&b""[..], 185_728_380_f32)) ); } @@ -284,11 +340,11 @@ mod complete { #[test] fn le_f64_tests() { assert_parse!( - le_f64(&[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00][..]), + le_f64.parse_peek(&[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00][..]), Ok((&b""[..], 0_f64)) ); assert_parse!( - le_f64(&[0x00, 0x00, 0x00, 0x10, 0xfb, 0x23, 0xa6, 0x41][..]), + le_f64.parse_peek(&[0x00, 0x00, 0x00, 0x10, 0xfb, 0x23, 0xa6, 0x41][..]), Ok((&b""[..], 185_728_392_f64)) ); } @@ -298,19 +354,19 @@ mod complete { use crate::binary::Endianness; fn be_tst16(i: &[u8]) -> IResult<&[u8], u16> { - u16(Endianness::Big).parse_next(i) + u16(Endianness::Big).parse_peek(i) } fn le_tst16(i: &[u8]) -> IResult<&[u8], u16> { - u16(Endianness::Little).parse_next(i) + u16(Endianness::Little).parse_peek(i) } assert_eq!(be_tst16(&[0x80, 0x00]), Ok((&b""[..], 32_768_u16))); assert_eq!(le_tst16(&[0x80, 0x00]), Ok((&b""[..], 128_u16))); fn be_tst32(i: &[u8]) -> IResult<&[u8], u32> { - u32(Endianness::Big).parse_next(i) + u32(Endianness::Big).parse_peek(i) } fn le_tst32(i: &[u8]) -> IResult<&[u8], u32> { - u32(Endianness::Little).parse_next(i) + u32(Endianness::Little).parse_peek(i) } assert_eq!( be_tst32(&[0x12, 0x00, 0x60, 0x00]), @@ -322,10 +378,10 @@ mod complete { ); fn be_tst64(i: &[u8]) -> IResult<&[u8], u64> { - u64(Endianness::Big).parse_next(i) + u64(Endianness::Big).parse_peek(i) } fn le_tst64(i: &[u8]) -> IResult<&[u8], u64> { - u64(Endianness::Little).parse_next(i) + u64(Endianness::Little).parse_peek(i) } assert_eq!( be_tst64(&[0x12, 0x00, 0x60, 0x00, 0x12, 0x00, 0x80, 0x00]), @@ -337,19 +393,19 @@ mod complete { ); fn be_tsti16(i: &[u8]) -> IResult<&[u8], i16> { - i16(Endianness::Big).parse_next(i) + i16(Endianness::Big).parse_peek(i) } fn le_tsti16(i: &[u8]) -> IResult<&[u8], i16> { - i16(Endianness::Little).parse_next(i) + i16(Endianness::Little).parse_peek(i) } assert_eq!(be_tsti16(&[0x00, 0x80]), Ok((&b""[..], 128_i16))); assert_eq!(le_tsti16(&[0x00, 0x80]), Ok((&b""[..], -32_768_i16))); fn be_tsti32(i: &[u8]) -> IResult<&[u8], i32> { - i32(Endianness::Big).parse_next(i) + i32(Endianness::Big).parse_peek(i) } fn le_tsti32(i: &[u8]) -> IResult<&[u8], i32> { - i32(Endianness::Little).parse_next(i) + i32(Endianness::Little).parse_peek(i) } assert_eq!( be_tsti32(&[0x00, 0x12, 0x60, 0x00]), @@ -361,10 +417,10 @@ mod complete { ); fn be_tsti64(i: &[u8]) -> IResult<&[u8], i64> { - i64(Endianness::Big).parse_next(i) + i64(Endianness::Big).parse_peek(i) } fn le_tsti64(i: &[u8]) -> IResult<&[u8], i64> { - i64(Endianness::Little).parse_next(i) + i64(Endianness::Little).parse_peek(i) } assert_eq!( be_tsti64(&[0x00, 0xFF, 0x60, 0x00, 0x12, 0x00, 0x80, 0x00]), @@ -380,7 +436,7 @@ mod complete { mod partial { use super::*; use crate::error::ErrMode; - use crate::error::Error; + use crate::error::InputError; use crate::error::Needed; #[cfg(feature = "alloc")] use crate::lib::std::vec::Vec; @@ -395,7 +451,7 @@ mod partial { macro_rules! assert_parse( ($left: expr, $right: expr) => { - let res: $crate::IResult<_, _, Error<_>> = $left; + let res: $crate::IResult<_, _, InputError<_>> = $left; assert_eq!(res, $right); }; ); @@ -403,23 +459,23 @@ mod partial { #[test] fn i8_tests() { assert_parse!( - be_i8(Partial::new(&[0x00][..])), + be_i8.parse_peek(Partial::new(&[0x00][..])), Ok((Partial::new(&b""[..]), 0)) ); assert_parse!( - be_i8(Partial::new(&[0x7f][..])), + be_i8.parse_peek(Partial::new(&[0x7f][..])), Ok((Partial::new(&b""[..]), 127)) ); assert_parse!( - be_i8(Partial::new(&[0xff][..])), + be_i8.parse_peek(Partial::new(&[0xff][..])), Ok((Partial::new(&b""[..]), -1)) ); assert_parse!( - be_i8(Partial::new(&[0x80][..])), + be_i8.parse_peek(Partial::new(&[0x80][..])), Ok((Partial::new(&b""[..]), -128)) ); assert_parse!( - be_i8(Partial::new(&[][..])), + be_i8.parse_peek(Partial::new(&[][..])), Err(ErrMode::Incomplete(Needed::new(1))) ); } @@ -427,27 +483,27 @@ mod partial { #[test] fn i16_tests() { assert_parse!( - be_i16(Partial::new(&[0x00, 0x00][..])), + be_i16.parse_peek(Partial::new(&[0x00, 0x00][..])), Ok((Partial::new(&b""[..]), 0)) ); assert_parse!( - be_i16(Partial::new(&[0x7f, 0xff][..])), + be_i16.parse_peek(Partial::new(&[0x7f, 0xff][..])), Ok((Partial::new(&b""[..]), 32_767_i16)) ); assert_parse!( - be_i16(Partial::new(&[0xff, 0xff][..])), + be_i16.parse_peek(Partial::new(&[0xff, 0xff][..])), Ok((Partial::new(&b""[..]), -1)) ); assert_parse!( - be_i16(Partial::new(&[0x80, 0x00][..])), + be_i16.parse_peek(Partial::new(&[0x80, 0x00][..])), Ok((Partial::new(&b""[..]), -32_768_i16)) ); assert_parse!( - be_i16(Partial::new(&[][..])), + be_i16.parse_peek(Partial::new(&[][..])), Err(ErrMode::Incomplete(Needed::new(2))) ); assert_parse!( - be_i16(Partial::new(&[0x00][..])), + be_i16.parse_peek(Partial::new(&[0x00][..])), Err(ErrMode::Incomplete(Needed::new(1))) ); } @@ -455,27 +511,27 @@ mod partial { #[test] fn u24_tests() { assert_parse!( - be_u24(Partial::new(&[0x00, 0x00, 0x00][..])), + be_u24.parse_peek(Partial::new(&[0x00, 0x00, 0x00][..])), Ok((Partial::new(&b""[..]), 0)) ); assert_parse!( - be_u24(Partial::new(&[0x00, 0xFF, 0xFF][..])), + be_u24.parse_peek(Partial::new(&[0x00, 0xFF, 0xFF][..])), Ok((Partial::new(&b""[..]), 65_535_u32)) ); assert_parse!( - be_u24(Partial::new(&[0x12, 0x34, 0x56][..])), + be_u24.parse_peek(Partial::new(&[0x12, 0x34, 0x56][..])), Ok((Partial::new(&b""[..]), 1_193_046_u32)) ); assert_parse!( - be_u24(Partial::new(&[][..])), + be_u24.parse_peek(Partial::new(&[][..])), Err(ErrMode::Incomplete(Needed::new(3))) ); assert_parse!( - be_u24(Partial::new(&[0x00][..])), + be_u24.parse_peek(Partial::new(&[0x00][..])), Err(ErrMode::Incomplete(Needed::new(2))) ); assert_parse!( - be_u24(Partial::new(&[0x00, 0x00][..])), + be_u24.parse_peek(Partial::new(&[0x00, 0x00][..])), Err(ErrMode::Incomplete(Needed::new(1))) ); } @@ -483,27 +539,27 @@ mod partial { #[test] fn i24_tests() { assert_parse!( - be_i24(Partial::new(&[0xFF, 0xFF, 0xFF][..])), + be_i24.parse_peek(Partial::new(&[0xFF, 0xFF, 0xFF][..])), Ok((Partial::new(&b""[..]), -1_i32)) ); assert_parse!( - be_i24(Partial::new(&[0xFF, 0x00, 0x00][..])), + be_i24.parse_peek(Partial::new(&[0xFF, 0x00, 0x00][..])), Ok((Partial::new(&b""[..]), -65_536_i32)) ); assert_parse!( - be_i24(Partial::new(&[0xED, 0xCB, 0xAA][..])), + be_i24.parse_peek(Partial::new(&[0xED, 0xCB, 0xAA][..])), Ok((Partial::new(&b""[..]), -1_193_046_i32)) ); assert_parse!( - be_i24(Partial::new(&[][..])), + be_i24.parse_peek(Partial::new(&[][..])), Err(ErrMode::Incomplete(Needed::new(3))) ); assert_parse!( - be_i24(Partial::new(&[0x00][..])), + be_i24.parse_peek(Partial::new(&[0x00][..])), Err(ErrMode::Incomplete(Needed::new(2))) ); assert_parse!( - be_i24(Partial::new(&[0x00, 0x00][..])), + be_i24.parse_peek(Partial::new(&[0x00, 0x00][..])), Err(ErrMode::Incomplete(Needed::new(1))) ); } @@ -511,35 +567,35 @@ mod partial { #[test] fn i32_tests() { assert_parse!( - be_i32(Partial::new(&[0x00, 0x00, 0x00, 0x00][..])), + be_i32.parse_peek(Partial::new(&[0x00, 0x00, 0x00, 0x00][..])), Ok((Partial::new(&b""[..]), 0)) ); assert_parse!( - be_i32(Partial::new(&[0x7f, 0xff, 0xff, 0xff][..])), + be_i32.parse_peek(Partial::new(&[0x7f, 0xff, 0xff, 0xff][..])), Ok((Partial::new(&b""[..]), 2_147_483_647_i32)) ); assert_parse!( - be_i32(Partial::new(&[0xff, 0xff, 0xff, 0xff][..])), + be_i32.parse_peek(Partial::new(&[0xff, 0xff, 0xff, 0xff][..])), Ok((Partial::new(&b""[..]), -1)) ); assert_parse!( - be_i32(Partial::new(&[0x80, 0x00, 0x00, 0x00][..])), + be_i32.parse_peek(Partial::new(&[0x80, 0x00, 0x00, 0x00][..])), Ok((Partial::new(&b""[..]), -2_147_483_648_i32)) ); assert_parse!( - be_i32(Partial::new(&[][..])), + be_i32.parse_peek(Partial::new(&[][..])), Err(ErrMode::Incomplete(Needed::new(4))) ); assert_parse!( - be_i32(Partial::new(&[0x00][..])), + be_i32.parse_peek(Partial::new(&[0x00][..])), Err(ErrMode::Incomplete(Needed::new(3))) ); assert_parse!( - be_i32(Partial::new(&[0x00, 0x00][..])), + be_i32.parse_peek(Partial::new(&[0x00, 0x00][..])), Err(ErrMode::Incomplete(Needed::new(2))) ); assert_parse!( - be_i32(Partial::new(&[0x00, 0x00, 0x00][..])), + be_i32.parse_peek(Partial::new(&[0x00, 0x00, 0x00][..])), Err(ErrMode::Incomplete(Needed::new(1))) ); } @@ -547,59 +603,59 @@ mod partial { #[test] fn i64_tests() { assert_parse!( - be_i64(Partial::new( + be_i64.parse_peek(Partial::new( &[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00][..] )), Ok((Partial::new(&b""[..]), 0)) ); assert_parse!( - be_i64(Partial::new( + be_i64.parse_peek(Partial::new( &[0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff][..] )), Ok((Partial::new(&b""[..]), 9_223_372_036_854_775_807_i64)) ); assert_parse!( - be_i64(Partial::new( + be_i64.parse_peek(Partial::new( &[0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff][..] )), Ok((Partial::new(&b""[..]), -1)) ); assert_parse!( - be_i64(Partial::new( + be_i64.parse_peek(Partial::new( &[0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00][..] )), Ok((Partial::new(&b""[..]), -9_223_372_036_854_775_808_i64)) ); assert_parse!( - be_i64(Partial::new(&[][..])), + be_i64.parse_peek(Partial::new(&[][..])), Err(ErrMode::Incomplete(Needed::new(8))) ); assert_parse!( - be_i64(Partial::new(&[0x00][..])), + be_i64.parse_peek(Partial::new(&[0x00][..])), Err(ErrMode::Incomplete(Needed::new(7))) ); assert_parse!( - be_i64(Partial::new(&[0x00, 0x00][..])), + be_i64.parse_peek(Partial::new(&[0x00, 0x00][..])), Err(ErrMode::Incomplete(Needed::new(6))) ); assert_parse!( - be_i64(Partial::new(&[0x00, 0x00, 0x00][..])), + be_i64.parse_peek(Partial::new(&[0x00, 0x00, 0x00][..])), Err(ErrMode::Incomplete(Needed::new(5))) ); assert_parse!( - be_i64(Partial::new(&[0x00, 0x00, 0x00, 0x00][..])), + be_i64.parse_peek(Partial::new(&[0x00, 0x00, 0x00, 0x00][..])), Err(ErrMode::Incomplete(Needed::new(4))) ); assert_parse!( - be_i64(Partial::new(&[0x00, 0x00, 0x00, 0x00, 0x00][..])), + be_i64.parse_peek(Partial::new(&[0x00, 0x00, 0x00, 0x00, 0x00][..])), Err(ErrMode::Incomplete(Needed::new(3))) ); assert_parse!( - be_i64(Partial::new(&[0x00, 0x00, 0x00, 0x00, 0x00, 0x00][..])), + be_i64.parse_peek(Partial::new(&[0x00, 0x00, 0x00, 0x00, 0x00, 0x00][..])), Err(ErrMode::Incomplete(Needed::new(2))) ); assert_parse!( - be_i64(Partial::new( + be_i64.parse_peek(Partial::new( &[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00][..] )), Err(ErrMode::Incomplete(Needed::new(1))) @@ -609,7 +665,7 @@ mod partial { #[test] fn i128_tests() { assert_parse!( - be_i128(Partial::new( + be_i128.parse_peek(Partial::new( &[ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 @@ -618,7 +674,7 @@ mod partial { Ok((Partial::new(&b""[..]), 0)) ); assert_parse!( - be_i128(Partial::new( + be_i128.parse_peek(Partial::new( &[ 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff @@ -630,7 +686,7 @@ mod partial { )) ); assert_parse!( - be_i128(Partial::new( + be_i128.parse_peek(Partial::new( &[ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff @@ -639,7 +695,7 @@ mod partial { Ok((Partial::new(&b""[..]), -1)) ); assert_parse!( - be_i128(Partial::new( + be_i128.parse_peek(Partial::new( &[ 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 @@ -651,77 +707,77 @@ mod partial { )) ); assert_parse!( - be_i128(Partial::new(&[][..])), + be_i128.parse_peek(Partial::new(&[][..])), Err(ErrMode::Incomplete(Needed::new(16))) ); assert_parse!( - be_i128(Partial::new(&[0x00][..])), + be_i128.parse_peek(Partial::new(&[0x00][..])), Err(ErrMode::Incomplete(Needed::new(15))) ); assert_parse!( - be_i128(Partial::new(&[0x00, 0x00][..])), + be_i128.parse_peek(Partial::new(&[0x00, 0x00][..])), Err(ErrMode::Incomplete(Needed::new(14))) ); assert_parse!( - be_i128(Partial::new(&[0x00, 0x00, 0x00][..])), + be_i128.parse_peek(Partial::new(&[0x00, 0x00, 0x00][..])), Err(ErrMode::Incomplete(Needed::new(13))) ); assert_parse!( - be_i128(Partial::new(&[0x00, 0x00, 0x00, 0x00][..])), + be_i128.parse_peek(Partial::new(&[0x00, 0x00, 0x00, 0x00][..])), Err(ErrMode::Incomplete(Needed::new(12))) ); assert_parse!( - be_i128(Partial::new(&[0x00, 0x00, 0x00, 0x00, 0x00][..])), + be_i128.parse_peek(Partial::new(&[0x00, 0x00, 0x00, 0x00, 0x00][..])), Err(ErrMode::Incomplete(Needed::new(11))) ); assert_parse!( - be_i128(Partial::new(&[0x00, 0x00, 0x00, 0x00, 0x00, 0x00][..])), + be_i128.parse_peek(Partial::new(&[0x00, 0x00, 0x00, 0x00, 0x00, 0x00][..])), Err(ErrMode::Incomplete(Needed::new(10))) ); assert_parse!( - be_i128(Partial::new( + be_i128.parse_peek(Partial::new( &[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00][..] )), Err(ErrMode::Incomplete(Needed::new(9))) ); assert_parse!( - be_i128(Partial::new( + be_i128.parse_peek(Partial::new( &[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00][..] )), Err(ErrMode::Incomplete(Needed::new(8))) ); assert_parse!( - be_i128(Partial::new( + be_i128.parse_peek(Partial::new( &[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00][..] )), Err(ErrMode::Incomplete(Needed::new(7))) ); assert_parse!( - be_i128(Partial::new( + be_i128.parse_peek(Partial::new( &[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00][..] )), Err(ErrMode::Incomplete(Needed::new(6))) ); assert_parse!( - be_i128(Partial::new( + be_i128.parse_peek(Partial::new( &[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00][..] )), Err(ErrMode::Incomplete(Needed::new(5))) ); assert_parse!( - be_i128(Partial::new( + be_i128.parse_peek(Partial::new( &[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00][..] )), Err(ErrMode::Incomplete(Needed::new(4))) ); assert_parse!( - be_i128(Partial::new( + be_i128.parse_peek(Partial::new( &[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00][..] )), Err(ErrMode::Incomplete(Needed::new(3))) ); assert_parse!( - be_i128(Partial::new( + be_i128.parse_peek(Partial::new( &[ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 @@ -730,7 +786,7 @@ mod partial { Err(ErrMode::Incomplete(Needed::new(2))) ); assert_parse!( - be_i128(Partial::new( + be_i128.parse_peek(Partial::new( &[ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 @@ -743,19 +799,19 @@ mod partial { #[test] fn le_i8_tests() { assert_parse!( - le_i8(Partial::new(&[0x00][..])), + le_i8.parse_peek(Partial::new(&[0x00][..])), Ok((Partial::new(&b""[..]), 0)) ); assert_parse!( - le_i8(Partial::new(&[0x7f][..])), + le_i8.parse_peek(Partial::new(&[0x7f][..])), Ok((Partial::new(&b""[..]), 127)) ); assert_parse!( - le_i8(Partial::new(&[0xff][..])), + le_i8.parse_peek(Partial::new(&[0xff][..])), Ok((Partial::new(&b""[..]), -1)) ); assert_parse!( - le_i8(Partial::new(&[0x80][..])), + le_i8.parse_peek(Partial::new(&[0x80][..])), Ok((Partial::new(&b""[..]), -128)) ); } @@ -763,19 +819,19 @@ mod partial { #[test] fn le_i16_tests() { assert_parse!( - le_i16(Partial::new(&[0x00, 0x00][..])), + le_i16.parse_peek(Partial::new(&[0x00, 0x00][..])), Ok((Partial::new(&b""[..]), 0)) ); assert_parse!( - le_i16(Partial::new(&[0xff, 0x7f][..])), + le_i16.parse_peek(Partial::new(&[0xff, 0x7f][..])), Ok((Partial::new(&b""[..]), 32_767_i16)) ); assert_parse!( - le_i16(Partial::new(&[0xff, 0xff][..])), + le_i16.parse_peek(Partial::new(&[0xff, 0xff][..])), Ok((Partial::new(&b""[..]), -1)) ); assert_parse!( - le_i16(Partial::new(&[0x00, 0x80][..])), + le_i16.parse_peek(Partial::new(&[0x00, 0x80][..])), Ok((Partial::new(&b""[..]), -32_768_i16)) ); } @@ -783,15 +839,15 @@ mod partial { #[test] fn le_u24_tests() { assert_parse!( - le_u24(Partial::new(&[0x00, 0x00, 0x00][..])), + le_u24.parse_peek(Partial::new(&[0x00, 0x00, 0x00][..])), Ok((Partial::new(&b""[..]), 0)) ); assert_parse!( - le_u24(Partial::new(&[0xFF, 0xFF, 0x00][..])), + le_u24.parse_peek(Partial::new(&[0xFF, 0xFF, 0x00][..])), Ok((Partial::new(&b""[..]), 65_535_u32)) ); assert_parse!( - le_u24(Partial::new(&[0x56, 0x34, 0x12][..])), + le_u24.parse_peek(Partial::new(&[0x56, 0x34, 0x12][..])), Ok((Partial::new(&b""[..]), 1_193_046_u32)) ); } @@ -799,15 +855,15 @@ mod partial { #[test] fn le_i24_tests() { assert_parse!( - le_i24(Partial::new(&[0xFF, 0xFF, 0xFF][..])), + le_i24.parse_peek(Partial::new(&[0xFF, 0xFF, 0xFF][..])), Ok((Partial::new(&b""[..]), -1_i32)) ); assert_parse!( - le_i24(Partial::new(&[0x00, 0x00, 0xFF][..])), + le_i24.parse_peek(Partial::new(&[0x00, 0x00, 0xFF][..])), Ok((Partial::new(&b""[..]), -65_536_i32)) ); assert_parse!( - le_i24(Partial::new(&[0xAA, 0xCB, 0xED][..])), + le_i24.parse_peek(Partial::new(&[0xAA, 0xCB, 0xED][..])), Ok((Partial::new(&b""[..]), -1_193_046_i32)) ); } @@ -815,19 +871,19 @@ mod partial { #[test] fn le_i32_tests() { assert_parse!( - le_i32(Partial::new(&[0x00, 0x00, 0x00, 0x00][..])), + le_i32.parse_peek(Partial::new(&[0x00, 0x00, 0x00, 0x00][..])), Ok((Partial::new(&b""[..]), 0)) ); assert_parse!( - le_i32(Partial::new(&[0xff, 0xff, 0xff, 0x7f][..])), + le_i32.parse_peek(Partial::new(&[0xff, 0xff, 0xff, 0x7f][..])), Ok((Partial::new(&b""[..]), 2_147_483_647_i32)) ); assert_parse!( - le_i32(Partial::new(&[0xff, 0xff, 0xff, 0xff][..])), + le_i32.parse_peek(Partial::new(&[0xff, 0xff, 0xff, 0xff][..])), Ok((Partial::new(&b""[..]), -1)) ); assert_parse!( - le_i32(Partial::new(&[0x00, 0x00, 0x00, 0x80][..])), + le_i32.parse_peek(Partial::new(&[0x00, 0x00, 0x00, 0x80][..])), Ok((Partial::new(&b""[..]), -2_147_483_648_i32)) ); } @@ -835,25 +891,25 @@ mod partial { #[test] fn le_i64_tests() { assert_parse!( - le_i64(Partial::new( + le_i64.parse_peek(Partial::new( &[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00][..] )), Ok((Partial::new(&b""[..]), 0)) ); assert_parse!( - le_i64(Partial::new( + le_i64.parse_peek(Partial::new( &[0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f][..] )), Ok((Partial::new(&b""[..]), 9_223_372_036_854_775_807_i64)) ); assert_parse!( - le_i64(Partial::new( + le_i64.parse_peek(Partial::new( &[0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff][..] )), Ok((Partial::new(&b""[..]), -1)) ); assert_parse!( - le_i64(Partial::new( + le_i64.parse_peek(Partial::new( &[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80][..] )), Ok((Partial::new(&b""[..]), -9_223_372_036_854_775_808_i64)) @@ -863,7 +919,7 @@ mod partial { #[test] fn le_i128_tests() { assert_parse!( - le_i128(Partial::new( + le_i128.parse_peek(Partial::new( &[ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 @@ -872,7 +928,7 @@ mod partial { Ok((Partial::new(&b""[..]), 0)) ); assert_parse!( - le_i128(Partial::new( + le_i128.parse_peek(Partial::new( &[ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f @@ -884,7 +940,7 @@ mod partial { )) ); assert_parse!( - le_i128(Partial::new( + le_i128.parse_peek(Partial::new( &[ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff @@ -893,7 +949,7 @@ mod partial { Ok((Partial::new(&b""[..]), -1)) ); assert_parse!( - le_i128(Partial::new( + le_i128.parse_peek(Partial::new( &[ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80 @@ -909,11 +965,11 @@ mod partial { #[test] fn be_f32_tests() { assert_parse!( - be_f32(Partial::new(&[0x00, 0x00, 0x00, 0x00][..])), + be_f32.parse_peek(Partial::new(&[0x00, 0x00, 0x00, 0x00][..])), Ok((Partial::new(&b""[..]), 0_f32)) ); assert_parse!( - be_f32(Partial::new(&[0x4d, 0x31, 0x1f, 0xd8][..])), + be_f32.parse_peek(Partial::new(&[0x4d, 0x31, 0x1f, 0xd8][..])), Ok((Partial::new(&b""[..]), 185_728_380_f32)) ); } @@ -921,13 +977,13 @@ mod partial { #[test] fn be_f64_tests() { assert_parse!( - be_f64(Partial::new( + be_f64.parse_peek(Partial::new( &[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00][..] )), Ok((Partial::new(&b""[..]), 0_f64)) ); assert_parse!( - be_f64(Partial::new( + be_f64.parse_peek(Partial::new( &[0x41, 0xa6, 0x23, 0xfb, 0x10, 0x00, 0x00, 0x00][..] )), Ok((Partial::new(&b""[..]), 185_728_392_f64)) @@ -937,11 +993,11 @@ mod partial { #[test] fn le_f32_tests() { assert_parse!( - le_f32(Partial::new(&[0x00, 0x00, 0x00, 0x00][..])), + le_f32.parse_peek(Partial::new(&[0x00, 0x00, 0x00, 0x00][..])), Ok((Partial::new(&b""[..]), 0_f32)) ); assert_parse!( - le_f32(Partial::new(&[0xd8, 0x1f, 0x31, 0x4d][..])), + le_f32.parse_peek(Partial::new(&[0xd8, 0x1f, 0x31, 0x4d][..])), Ok((Partial::new(&b""[..]), 185_728_380_f32)) ); } @@ -949,13 +1005,13 @@ mod partial { #[test] fn le_f64_tests() { assert_parse!( - le_f64(Partial::new( + le_f64.parse_peek(Partial::new( &[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00][..] )), Ok((Partial::new(&b""[..]), 0_f64)) ); assert_parse!( - le_f64(Partial::new( + le_f64.parse_peek(Partial::new( &[0x00, 0x00, 0x00, 0x10, 0xfb, 0x23, 0xa6, 0x41][..] )), Ok((Partial::new(&b""[..]), 185_728_392_f64)) @@ -967,10 +1023,10 @@ mod partial { use crate::binary::Endianness; fn be_tst16(i: Partial<&[u8]>) -> IResult<Partial<&[u8]>, u16> { - u16(Endianness::Big).parse_next(i) + u16(Endianness::Big).parse_peek(i) } fn le_tst16(i: Partial<&[u8]>) -> IResult<Partial<&[u8]>, u16> { - u16(Endianness::Little).parse_next(i) + u16(Endianness::Little).parse_peek(i) } assert_eq!( be_tst16(Partial::new(&[0x80, 0x00])), @@ -982,10 +1038,10 @@ mod partial { ); fn be_tst32(i: Partial<&[u8]>) -> IResult<Partial<&[u8]>, u32> { - u32(Endianness::Big).parse_next(i) + u32(Endianness::Big).parse_peek(i) } fn le_tst32(i: Partial<&[u8]>) -> IResult<Partial<&[u8]>, u32> { - u32(Endianness::Little).parse_next(i) + u32(Endianness::Little).parse_peek(i) } assert_eq!( be_tst32(Partial::new(&[0x12, 0x00, 0x60, 0x00])), @@ -997,10 +1053,10 @@ mod partial { ); fn be_tst64(i: Partial<&[u8]>) -> IResult<Partial<&[u8]>, u64> { - u64(Endianness::Big).parse_next(i) + u64(Endianness::Big).parse_peek(i) } fn le_tst64(i: Partial<&[u8]>) -> IResult<Partial<&[u8]>, u64> { - u64(Endianness::Little).parse_next(i) + u64(Endianness::Little).parse_peek(i) } assert_eq!( be_tst64(Partial::new(&[ @@ -1016,10 +1072,10 @@ mod partial { ); fn be_tsti16(i: Partial<&[u8]>) -> IResult<Partial<&[u8]>, i16> { - i16(Endianness::Big).parse_next(i) + i16(Endianness::Big).parse_peek(i) } fn le_tsti16(i: Partial<&[u8]>) -> IResult<Partial<&[u8]>, i16> { - i16(Endianness::Little).parse_next(i) + i16(Endianness::Little).parse_peek(i) } assert_eq!( be_tsti16(Partial::new(&[0x00, 0x80])), @@ -1031,10 +1087,10 @@ mod partial { ); fn be_tsti32(i: Partial<&[u8]>) -> IResult<Partial<&[u8]>, i32> { - i32(Endianness::Big).parse_next(i) + i32(Endianness::Big).parse_peek(i) } fn le_tsti32(i: Partial<&[u8]>) -> IResult<Partial<&[u8]>, i32> { - i32(Endianness::Little).parse_next(i) + i32(Endianness::Little).parse_peek(i) } assert_eq!( be_tsti32(Partial::new(&[0x00, 0x12, 0x60, 0x00])), @@ -1046,10 +1102,10 @@ mod partial { ); fn be_tsti64(i: Partial<&[u8]>) -> IResult<Partial<&[u8]>, i64> { - i64(Endianness::Big).parse_next(i) + i64(Endianness::Big).parse_peek(i) } fn le_tsti64(i: Partial<&[u8]>) -> IResult<Partial<&[u8]>, i64> { - i64(Endianness::Little).parse_next(i) + i64(Endianness::Little).parse_peek(i) } assert_eq!( be_tsti64(Partial::new(&[ @@ -1072,11 +1128,11 @@ mod partial { digit .try_map(str::from_utf8) .try_map(FromStr::from_str) - .parse_next(i) + .parse_peek(i) } fn cnt(i: Partial<&[u8]>) -> IResult<Partial<&[u8]>, Vec<&[u8]>> { - length_count(number, "abc").parse_next(i) + length_count(unpeek(number), "abc").parse_peek(i) } assert_eq!( @@ -1094,14 +1150,14 @@ mod partial { assert_eq!( cnt(Partial::new(&b"xxx"[..])), Err(ErrMode::Backtrack(error_position!( - Partial::new(&b"xxx"[..]), + &Partial::new(&b"xxx"[..]), ErrorKind::Slice ))) ); assert_eq!( cnt(Partial::new(&b"2abcxxx"[..])), Err(ErrMode::Backtrack(error_position!( - Partial::new(&b"xxx"[..]), + &Partial::new(&b"xxx"[..]), ErrorKind::Tag ))) ); @@ -1113,11 +1169,11 @@ mod partial { digit .try_map(str::from_utf8) .try_map(FromStr::from_str) - .parse_next(i) + .parse_peek(i) } fn take(i: Partial<&[u8]>) -> IResult<Partial<&[u8]>, &[u8]> { - length_data(number).parse_next(i) + length_data(unpeek(number)).parse_peek(i) } assert_eq!( @@ -1131,7 +1187,7 @@ mod partial { assert_eq!( take(Partial::new(&b"xxx"[..])), Err(ErrMode::Backtrack(error_position!( - Partial::new(&b"xxx"[..]), + &Partial::new(&b"xxx"[..]), ErrorKind::Slice ))) ); @@ -1146,10 +1202,10 @@ mod partial { use crate::stream::StreamIsPartial; fn length_value_1(i: Partial<&[u8]>) -> IResult<Partial<&[u8]>, u16> { - length_value(be_u8, be_u16).parse_next(i) + length_value(be_u8, be_u16).parse_peek(i) } fn length_value_2(i: Partial<&[u8]>) -> IResult<Partial<&[u8]>, (u8, u8)> { - length_value(be_u8, (be_u8, be_u8)).parse_next(i) + length_value(be_u8, (be_u8, be_u8)).parse_peek(i) } let mut empty_complete = Partial::new(&b""[..]); @@ -1159,14 +1215,14 @@ mod partial { assert_eq!( length_value_1(Partial::new(&i1)), Err(ErrMode::Backtrack(error_position!( - empty_complete, + &empty_complete, ErrorKind::Slice ))) ); assert_eq!( length_value_2(Partial::new(&i1)), Err(ErrMode::Backtrack(error_position!( - empty_complete, + &empty_complete, ErrorKind::Token ))) ); @@ -1178,14 +1234,14 @@ mod partial { assert_eq!( length_value_1(Partial::new(&i2)), Err(ErrMode::Backtrack(error_position!( - middle_complete, + &middle_complete, ErrorKind::Slice ))) ); assert_eq!( length_value_2(Partial::new(&i2)), Err(ErrMode::Backtrack(error_position!( - empty_complete, + &empty_complete, ErrorKind::Token ))) ); |