From 69c0d5bb03a50e9bc609883569f28984ab34d7f4 Mon Sep 17 00:00:00 2001 From: Marc de Jonge Date: Thu, 30 Jan 2025 09:51:22 +0100 Subject: [PATCH 1/3] Change the standard Input impl to support any slice The main change is that the Item is a reference instead of a copy --- src/bits/complete.rs | 14 +-- src/bits/streaming.rs | 14 +-- src/bytes/complete.rs | 6 +- src/bytes/mod.rs | 21 ++--- src/bytes/streaming.rs | 19 ++-- src/number/complete.rs | 182 +++++++++++++++++++------------------- src/number/mod.rs | 190 ++++++++++++++++++++-------------------- src/number/streaming.rs | 176 ++++++++++++++++++------------------- src/traits.rs | 78 +++++++++++++---- tests/ini.rs | 6 +- 10 files changed, 374 insertions(+), 332 deletions(-) diff --git a/src/bits/complete.rs b/src/bits/complete.rs index a99ad8acc..18fb9b167 100644 --- a/src/bits/complete.rs +++ b/src/bits/complete.rs @@ -30,11 +30,11 @@ use crate::traits::{Input, ToUsize}; /// // Tries to consume 12 bits but only 8 are available /// assert_eq!(parser(([0b00010010].as_ref(), 0), 12), Err(nom::Err::Error(Error{input: ([0b00010010].as_ref(), 0), code: ErrorKind::Eof }))); /// ``` -pub fn take>( +pub fn take<'a, I, O, C, E: ParseError<(I, usize)>>( count: C, ) -> impl Fn((I, usize)) -> IResult<(I, usize), O, E> where - I: Input, + I: Input, C: ToUsize, O: From + AddAssign + Shl + Shr, { @@ -59,7 +59,7 @@ where break; } let val: O = if offset == 0 { - byte.into() + (*byte).into() } else { ((byte << offset) >> offset).into() }; @@ -80,12 +80,12 @@ where } /// Generates a parser taking `count` bits and comparing them to `pattern` -pub fn tag>( +pub fn tag<'a, I, O, C, E: ParseError<(I, usize)>>( pattern: O, count: C, ) -> impl Fn((I, usize)) -> IResult<(I, usize), O, E> where - I: Input + Clone, + I: Input + Clone, C: ToUsize, O: From + AddAssign + Shl + Shr + PartialEq, { @@ -118,9 +118,9 @@ where /// assert_eq!(parse(([0b10000000].as_ref(), 0)), Ok((([0b10000000].as_ref(), 1), true))); /// assert_eq!(parse(([0b10000000].as_ref(), 1)), Ok((([0b10000000].as_ref(), 2), false))); /// ``` -pub fn bool>(input: (I, usize)) -> IResult<(I, usize), bool, E> +pub fn bool<'a, I, E: ParseError<(I, usize)>>(input: (I, usize)) -> IResult<(I, usize), bool, E> where - I: Input, + I: Input, { let (res, bit): (_, u32) = take(1usize)(input)?; Ok((res, bit != 0)) diff --git a/src/bits/streaming.rs b/src/bits/streaming.rs index c9215956a..f1bae8884 100644 --- a/src/bits/streaming.rs +++ b/src/bits/streaming.rs @@ -7,11 +7,11 @@ use crate::lib::std::ops::{AddAssign, Div, Shl, Shr}; use crate::traits::{Input, ToUsize}; /// Generates a parser taking `count` bits -pub fn take>( +pub fn take<'a, I, O, C, E: ParseError<(I, usize)>>( count: C, ) -> impl Fn((I, usize)) -> IResult<(I, usize), O, E> where - I: Input, + I: Input, C: ToUsize, O: From + AddAssign + Shl + Shr, { @@ -34,7 +34,7 @@ where break; } let val: O = if offset == 0 { - byte.into() + (*byte).into() } else { ((byte << offset) >> offset).into() }; @@ -56,12 +56,12 @@ where } /// Generates a parser taking `count` bits and comparing them to `pattern` -pub fn tag>( +pub fn tag<'a, I, O, C, E: ParseError<(I, usize)>>( pattern: O, count: C, ) -> impl Fn((I, usize)) -> IResult<(I, usize), O, E> where - I: Input + Clone, + I: Input + Clone, C: ToUsize, O: From + AddAssign + Shl + Shr + PartialEq, { @@ -94,9 +94,9 @@ where /// assert_eq!(parse(([0b10000000].as_ref(), 0)), Ok((([0b10000000].as_ref(), 1), true))); /// assert_eq!(parse(([0b10000000].as_ref(), 1)), Ok((([0b10000000].as_ref(), 2), false))); /// ``` -pub fn bool>(input: (I, usize)) -> IResult<(I, usize), bool, E> +pub fn bool<'a, I, E: ParseError<(I, usize)>>(input: (I, usize)) -> IResult<(I, usize), bool, E> where - I: Input, + I: Input, { let (res, bit): (_, u32) = take(1usize)(input)?; Ok((res, bit != 0)) diff --git a/src/bytes/complete.rs b/src/bytes/complete.rs index 28cbb717d..8f99244d3 100644 --- a/src/bytes/complete.rs +++ b/src/bytes/complete.rs @@ -5,10 +5,10 @@ use core::marker::PhantomData; use crate::error::ParseError; use crate::internal::{IResult, Parser}; use crate::traits::{Compare, FindSubstring, FindToken, ToUsize}; -use crate::Complete; use crate::Emit; use crate::Input; use crate::OutputM; +use crate::{Complete, IntoInput}; /// Recognizes a pattern /// @@ -358,8 +358,8 @@ where /// ``` pub fn take_until>(tag: T) -> impl FnMut(I) -> IResult where - I: Input + FindSubstring, - T: Input + Clone, + I: Input + FindSubstring, + T: IntoInput, { let mut parser = super::take_until(tag); diff --git a/src/bytes/mod.rs b/src/bytes/mod.rs index 96732cd57..0c0b79820 100644 --- a/src/bytes/mod.rs +++ b/src/bytes/mod.rs @@ -12,7 +12,6 @@ use crate::error::ParseError; use crate::internal::{Err, Needed, Parser}; use crate::lib::std::result::Result::*; use crate::traits::{Compare, CompareResult}; -use crate::AsChar; use crate::Check; use crate::ExtendInto; use crate::FindSubstring; @@ -23,6 +22,7 @@ use crate::Mode; use crate::OutputM; use crate::OutputMode; use crate::ToUsize; +use crate::{AsChar, IntoInput}; /// Recognizes a pattern. /// @@ -44,11 +44,11 @@ use crate::ToUsize; /// ``` pub fn tag>(tag: T) -> impl Parser where - I: Input + Compare, - T: Input + Clone, + I: Input + Compare, + T: IntoInput, { Tag { - tag, + tag: tag.into_input(), e: PhantomData, } } @@ -113,11 +113,11 @@ where /// ``` pub fn tag_no_case>(tag: T) -> impl Parser where - I: Input + Compare, - T: Input + Clone, + I: Input + Compare, + T: IntoInput, { TagNoCase { - tag, + tag: tag.into_input(), e: PhantomData, } } @@ -595,11 +595,12 @@ where /// ``` pub fn take_until>(tag: T) -> impl Parser where - I: Input + FindSubstring, - T: Clone, + I: Input + FindSubstring, + T: IntoInput, + T::Input: Clone, { TakeUntil { - tag, + tag: tag.into_input(), e: PhantomData, } } diff --git a/src/bytes/streaming.rs b/src/bytes/streaming.rs index e240b5e52..d07a6de4b 100644 --- a/src/bytes/streaming.rs +++ b/src/bytes/streaming.rs @@ -5,10 +5,10 @@ use core::marker::PhantomData; use crate::error::ParseError; use crate::internal::{IResult, Parser}; use crate::traits::{Compare, FindSubstring, FindToken, ToUsize}; -use crate::Emit; use crate::Input; use crate::OutputM; use crate::Streaming; +use crate::{Emit, IntoInput}; /// Recognizes a pattern. /// @@ -30,12 +30,12 @@ use crate::Streaming; /// ``` pub fn tag>(tag: T) -> impl Fn(I) -> IResult where - I: Input + Compare, - T: Input + Clone, + I: Input + Compare, + T: IntoInput + Clone, { move |i: I| { let mut parser = super::Tag { - tag: tag.clone(), + tag: tag.clone().into_input(), e: PhantomData, }; @@ -64,12 +64,12 @@ where /// ``` pub fn tag_no_case>(tag: T) -> impl Fn(I) -> IResult where - I: Input + Compare, - T: Input + Clone, + I: Input + Compare, + T: IntoInput + Clone, { move |i: I| { let mut parser = super::TagNoCase { - tag: tag.clone(), + tag: tag.clone().into_input(), e: PhantomData, }; @@ -369,8 +369,9 @@ where /// ``` pub fn take_until>(tag: T) -> impl FnMut(I) -> IResult where - I: Input + FindSubstring, - T: Clone, + I: Input + FindSubstring, + T: IntoInput, + T::Input: Clone, { let mut parser = super::take_until(tag); diff --git a/src/number/complete.rs b/src/number/complete.rs index d8a2a978e..9263a7866 100644 --- a/src/number/complete.rs +++ b/src/number/complete.rs @@ -27,9 +27,9 @@ use crate::traits::{AsBytes, AsChar, Compare, Input, Offset}; /// assert_eq!(parser(&b""[..]), Err(Err::Error((&[][..], ErrorKind::Eof)))); /// ``` #[inline] -pub fn be_u8>(input: I) -> IResult +pub fn be_u8<'a,I, E: ParseError>(input: I) -> IResult where - I: Input, + I: Input, { be_uint(input, 1) } @@ -50,9 +50,9 @@ where /// assert_eq!(parser(&b"\x01"[..]), Err(Err::Error((&[0x01][..], ErrorKind::Eof)))); /// ``` #[inline] -pub fn be_u16>(input: I) -> IResult +pub fn be_u16<'a, I, E: ParseError>(input: I) -> IResult where - I: Input, + I: Input, { be_uint(input, 2) } @@ -73,9 +73,9 @@ where /// assert_eq!(parser(&b"\x01"[..]), Err(Err::Error((&[0x01][..], ErrorKind::Eof)))); /// ``` #[inline] -pub fn be_u24>(input: I) -> IResult +pub fn be_u24<'a, I, E: ParseError>(input: I) -> IResult where - I: Input, + I: Input, { be_uint(input, 3) } @@ -96,9 +96,9 @@ where /// assert_eq!(parser(&b"\x01"[..]), Err(Err::Error((&[0x01][..], ErrorKind::Eof)))); /// ``` #[inline] -pub fn be_u32>(input: I) -> IResult +pub fn be_u32<'a, I, E: ParseError>(input: I) -> IResult where - I: Input, + I: Input, { be_uint(input, 4) } @@ -119,9 +119,9 @@ where /// assert_eq!(parser(&b"\x01"[..]), Err(Err::Error((&[0x01][..], ErrorKind::Eof)))); /// ``` #[inline] -pub fn be_u64>(input: I) -> IResult +pub fn be_u64<'a, I, E: ParseError>(input: I) -> IResult where - I: Input, + I: Input, { be_uint(input, 8) } @@ -142,17 +142,17 @@ where /// assert_eq!(parser(&b"\x01"[..]), Err(Err::Error((&[0x01][..], ErrorKind::Eof)))); /// ``` #[inline] -pub fn be_u128>(input: I) -> IResult +pub fn be_u128<'a, I, E: ParseError>(input: I) -> IResult where - I: Input, + I: Input, { be_uint(input, 16) } #[inline] -fn be_uint>(input: I, bound: usize) -> IResult +fn be_uint<'a, I, Uint, E: ParseError>(input: I, bound: usize) -> IResult where - I: Input, + I: Input, Uint: Default + Shl + Add + From, { super::be_uint(bound).parse_complete(input) @@ -174,9 +174,9 @@ where /// assert_eq!(parser(&b""[..]), Err(Err::Error((&[][..], ErrorKind::Eof)))); /// ``` #[inline] -pub fn be_i8>(input: I) -> IResult +pub fn be_i8<'a, I, E: ParseError>(input: I) -> IResult where - I: Input, + I: Input, { be_u8.map(|x| x as i8).parse(input) } @@ -197,9 +197,9 @@ where /// assert_eq!(parser(&b"\x01"[..]), Err(Err::Error((&[0x01][..], ErrorKind::Eof)))); /// ``` #[inline] -pub fn be_i16>(input: I) -> IResult +pub fn be_i16<'a, I, E: ParseError>(input: I) -> IResult where - I: Input, + I: Input, { be_u16.map(|x| x as i16).parse(input) } @@ -220,9 +220,9 @@ where /// assert_eq!(parser(&b"\x01"[..]), Err(Err::Error((&[0x01][..], ErrorKind::Eof)))); /// ``` #[inline] -pub fn be_i24>(input: I) -> IResult +pub fn be_i24<'a, I, E: ParseError>(input: I) -> IResult where - I: Input, + I: Input, { // Same as the unsigned version but we need to sign-extend manually here be_u24 @@ -252,9 +252,9 @@ where /// assert_eq!(parser(&b"\x01"[..]), Err(Err::Error((&[0x01][..], ErrorKind::Eof)))); /// ``` #[inline] -pub fn be_i32>(input: I) -> IResult +pub fn be_i32<'a, I, E: ParseError>(input: I) -> IResult where - I: Input, + I: Input, { be_u32.map(|x| x as i32).parse(input) } @@ -275,9 +275,9 @@ where /// assert_eq!(parser(&b"\x01"[..]), Err(Err::Error((&[0x01][..], ErrorKind::Eof)))); /// ``` #[inline] -pub fn be_i64>(input: I) -> IResult +pub fn be_i64<'a, I, E: ParseError>(input: I) -> IResult where - I: Input, + I: Input, { be_u64.map(|x| x as i64).parse(input) } @@ -298,9 +298,9 @@ where /// assert_eq!(parser(&b"\x01"[..]), Err(Err::Error((&[0x01][..], ErrorKind::Eof)))); /// ``` #[inline] -pub fn be_i128>(input: I) -> IResult +pub fn be_i128<'a, I, E: ParseError>(input: I) -> IResult where - I: Input, + I: Input, { be_u128.map(|x| x as i128).parse(input) } @@ -321,9 +321,9 @@ where /// assert_eq!(parser(&b""[..]), Err(Err::Error((&[][..], ErrorKind::Eof)))); /// ``` #[inline] -pub fn le_u8>(input: I) -> IResult +pub fn le_u8<'a, I, E: ParseError>(input: I) -> IResult where - I: Input, + I: Input, { le_uint(input, 1) } @@ -344,9 +344,9 @@ where /// assert_eq!(parser(&b"\x01"[..]), Err(Err::Error((&[0x01][..], ErrorKind::Eof)))); /// ``` #[inline] -pub fn le_u16>(input: I) -> IResult +pub fn le_u16<'a, I, E: ParseError>(input: I) -> IResult where - I: Input, + I: Input, { le_uint(input, 2) } @@ -367,9 +367,9 @@ where /// assert_eq!(parser(&b"\x01"[..]), Err(Err::Error((&[0x01][..], ErrorKind::Eof)))); /// ``` #[inline] -pub fn le_u24>(input: I) -> IResult +pub fn le_u24<'a, I, E: ParseError>(input: I) -> IResult where - I: Input, + I: Input, { le_uint(input, 3) } @@ -390,9 +390,9 @@ where /// assert_eq!(parser(&b"\x01"[..]), Err(Err::Error((&[0x01][..], ErrorKind::Eof)))); /// ``` #[inline] -pub fn le_u32>(input: I) -> IResult +pub fn le_u32<'a, I, E: ParseError>(input: I) -> IResult where - I: Input, + I: Input, { le_uint(input, 4) } @@ -413,9 +413,9 @@ where /// assert_eq!(parser(&b"\x01"[..]), Err(Err::Error((&[0x01][..], ErrorKind::Eof)))); /// ``` #[inline] -pub fn le_u64>(input: I) -> IResult +pub fn le_u64<'a, I, E: ParseError>(input: I) -> IResult where - I: Input, + I: Input, { le_uint(input, 8) } @@ -436,17 +436,17 @@ where /// assert_eq!(parser(&b"\x01"[..]), Err(Err::Error((&[0x01][..], ErrorKind::Eof)))); /// ``` #[inline] -pub fn le_u128>(input: I) -> IResult +pub fn le_u128<'a, I, E: ParseError>(input: I) -> IResult where - I: Input, + I: Input, { le_uint(input, 16) } #[inline] -fn le_uint>(input: I, bound: usize) -> IResult +fn le_uint<'a, I, Uint, E: ParseError>(input: I, bound: usize) -> IResult where - I: Input, + I: Input, Uint: Default + Shl + Add + From, { super::le_uint(bound).parse_complete(input) @@ -468,9 +468,9 @@ where /// assert_eq!(parser(&b""[..]), Err(Err::Error((&[][..], ErrorKind::Eof)))); /// ``` #[inline] -pub fn le_i8>(input: I) -> IResult +pub fn le_i8<'a, I, E: ParseError>(input: I) -> IResult where - I: Input, + I: Input, { be_u8.map(|x| x as i8).parse(input) } @@ -491,9 +491,9 @@ where /// assert_eq!(parser(&b"\x01"[..]), Err(Err::Error((&[0x01][..], ErrorKind::Eof)))); /// ``` #[inline] -pub fn le_i16>(input: I) -> IResult +pub fn le_i16<'a, I, E: ParseError>(input: I) -> IResult where - I: Input, + I: Input, { le_u16.map(|x| x as i16).parse(input) } @@ -514,9 +514,9 @@ where /// assert_eq!(parser(&b"\x01"[..]), Err(Err::Error((&[0x01][..], ErrorKind::Eof)))); /// ``` #[inline] -pub fn le_i24>(input: I) -> IResult +pub fn le_i24<'a, I, E: ParseError>(input: I) -> IResult where - I: Input, + I: Input, { // Same as the unsigned version but we need to sign-extend manually here le_u24 @@ -546,9 +546,9 @@ where /// assert_eq!(parser(&b"\x01"[..]), Err(Err::Error((&[0x01][..], ErrorKind::Eof)))); /// ``` #[inline] -pub fn le_i32>(input: I) -> IResult +pub fn le_i32<'a, I, E: ParseError>(input: I) -> IResult where - I: Input, + I: Input, { le_u32.map(|x| x as i32).parse(input) } @@ -569,9 +569,9 @@ where /// assert_eq!(parser(&b"\x01"[..]), Err(Err::Error((&[0x01][..], ErrorKind::Eof)))); /// ``` #[inline] -pub fn le_i64>(input: I) -> IResult +pub fn le_i64<'a, I, E: ParseError>(input: I) -> IResult where - I: Input, + I: Input, { le_u64.map(|x| x as i64).parse(input) } @@ -592,9 +592,9 @@ where /// assert_eq!(parser(&b"\x01"[..]), Err(Err::Error((&[0x01][..], ErrorKind::Eof)))); /// ``` #[inline] -pub fn le_i128>(input: I) -> IResult +pub fn le_i128<'a, I, E: ParseError>(input: I) -> IResult where - I: Input, + I: Input, { le_u128.map(|x| x as i128).parse(input) } @@ -616,9 +616,9 @@ where /// assert_eq!(parser(&b""[..]), Err(Err::Error((&[][..], ErrorKind::Eof)))); /// ``` #[inline] -pub fn u8>(input: I) -> IResult +pub fn u8<'a, I, E: ParseError>(input: I) -> IResult where - I: Input, + I: Input, { super::u8().parse_complete(input) } @@ -649,11 +649,11 @@ where /// assert_eq!(le_u16(&b"\x01"[..]), Err(Err::Error((&[0x01][..], ErrorKind::Eof)))); /// ``` #[inline] -pub fn u16>( +pub fn u16<'a, I, E: ParseError>( endian: crate::number::Endianness, ) -> impl Fn(I) -> IResult where - I: Input, + I: Input, { move |input| super::u16(endian).parse_complete(input) } @@ -683,11 +683,11 @@ where /// assert_eq!(le_u24(&b"\x01"[..]), Err(Err::Error((&[0x01][..], ErrorKind::Eof)))); /// ``` #[inline] -pub fn u24>( +pub fn u24<'a, I, E: ParseError>( endian: crate::number::Endianness, ) -> impl Fn(I) -> IResult where - I: Input, + I: Input, { move |input| super::u24(endian).parse_complete(input) } @@ -717,11 +717,11 @@ where /// assert_eq!(le_u32(&b"\x01"[..]), Err(Err::Error((&[0x01][..], ErrorKind::Eof)))); /// ``` #[inline] -pub fn u32>( +pub fn u32<'a, I, E: ParseError>( endian: crate::number::Endianness, ) -> impl Fn(I) -> IResult where - I: Input, + I: Input, { move |input| super::u32(endian).parse_complete(input) } @@ -751,11 +751,11 @@ where /// assert_eq!(le_u64(&b"\x01"[..]), Err(Err::Error((&[0x01][..], ErrorKind::Eof)))); /// ``` #[inline] -pub fn u64>( +pub fn u64<'a, I, E: ParseError>( endian: crate::number::Endianness, ) -> impl Fn(I) -> IResult where - I: Input, + I: Input, { move |input| super::u64(endian).parse_complete(input) } @@ -785,11 +785,11 @@ where /// assert_eq!(le_u128(&b"\x01"[..]), Err(Err::Error((&[0x01][..], ErrorKind::Eof)))); /// ``` #[inline] -pub fn u128>( +pub fn u128<'a, I, E: ParseError>( endian: crate::number::Endianness, ) -> impl Fn(I) -> IResult where - I: Input, + I: Input, { move |input| super::u128(endian).parse_complete(input) } @@ -811,9 +811,9 @@ where /// assert_eq!(parser(&b""[..]), Err(Err::Error((&[][..], ErrorKind::Eof)))); /// ``` #[inline] -pub fn i8>(i: I) -> IResult +pub fn i8<'a, I, E: ParseError>(i: I) -> IResult where - I: Input, + I: Input, { super::u8().map(|x| x as i8).parse_complete(i) } @@ -843,11 +843,11 @@ where /// assert_eq!(le_i16(&b"\x01"[..]), Err(Err::Error((&[0x01][..], ErrorKind::Eof)))); /// ``` #[inline] -pub fn i16>( +pub fn i16<'a, I, E: ParseError>( endian: crate::number::Endianness, ) -> impl Fn(I) -> IResult where - I: Input, + I: Input, { move |input| super::i16(endian).parse_complete(input) } @@ -877,11 +877,11 @@ where /// assert_eq!(le_i24(&b"\x01"[..]), Err(Err::Error((&[0x01][..], ErrorKind::Eof)))); /// ``` #[inline] -pub fn i24>( +pub fn i24<'a, I, E: ParseError>( endian: crate::number::Endianness, ) -> impl Fn(I) -> IResult where - I: Input, + I: Input, { move |input| super::i24(endian).parse_complete(input) } @@ -911,11 +911,11 @@ where /// assert_eq!(le_i32(&b"\x01"[..]), Err(Err::Error((&[0x01][..], ErrorKind::Eof)))); /// ``` #[inline] -pub fn i32>( +pub fn i32<'a, I, E: ParseError>( endian: crate::number::Endianness, ) -> impl Fn(I) -> IResult where - I: Input, + I: Input, { move |input| super::i32(endian).parse_complete(input) } @@ -945,11 +945,11 @@ where /// assert_eq!(le_i64(&b"\x01"[..]), Err(Err::Error((&[0x01][..], ErrorKind::Eof)))); /// ``` #[inline] -pub fn i64>( +pub fn i64<'a, I, E: ParseError>( endian: crate::number::Endianness, ) -> impl Fn(I) -> IResult where - I: Input, + I: Input, { move |input| super::i64(endian).parse_complete(input) } @@ -979,11 +979,11 @@ where /// assert_eq!(le_i128(&b"\x01"[..]), Err(Err::Error((&[0x01][..], ErrorKind::Eof)))); /// ``` #[inline] -pub fn i128>( +pub fn i128<'a, I, E: ParseError>( endian: crate::number::Endianness, ) -> impl Fn(I) -> IResult where - I: Input, + I: Input, { move |input| super::i128(endian).parse_complete(input) } @@ -1004,9 +1004,9 @@ where /// assert_eq!(parser(&b"abc"[..]), Err(Err::Error((&b"abc"[..], ErrorKind::Eof)))); /// ``` #[inline] -pub fn be_f32>(input: I) -> IResult +pub fn be_f32<'a, I, E: ParseError>(input: I) -> IResult where - I: Input, + I: Input, { match be_u32(input) { Err(e) => Err(e), @@ -1030,9 +1030,9 @@ where /// assert_eq!(parser(&b"abc"[..]), Err(Err::Error((&b"abc"[..], ErrorKind::Eof)))); /// ``` #[inline] -pub fn be_f64>(input: I) -> IResult +pub fn be_f64<'a, I, E: ParseError>(input: I) -> IResult where - I: Input, + I: Input, { match be_u64(input) { Err(e) => Err(e), @@ -1056,9 +1056,9 @@ where /// assert_eq!(parser(&b"abc"[..]), Err(Err::Error((&b"abc"[..], ErrorKind::Eof)))); /// ``` #[inline] -pub fn le_f32>(input: I) -> IResult +pub fn le_f32<'a, I, E: ParseError>(input: I) -> IResult where - I: Input, + I: Input, { match le_u32(input) { Err(e) => Err(e), @@ -1082,9 +1082,9 @@ where /// assert_eq!(parser(&b"abc"[..]), Err(Err::Error((&b"abc"[..], ErrorKind::Eof)))); /// ``` #[inline] -pub fn le_f64>(input: I) -> IResult +pub fn le_f64<'a, I, E: ParseError>(input: I) -> IResult where - I: Input, + I: Input, { match le_u64(input) { Err(e) => Err(e), @@ -1117,9 +1117,9 @@ where /// assert_eq!(le_f32(&b"abc"[..]), Err(Err::Error((&b"abc"[..], ErrorKind::Eof)))); /// ``` #[inline] -pub fn f32>(endian: crate::number::Endianness) -> fn(I) -> IResult +pub fn f32<'a, I, E: ParseError>(endian: crate::number::Endianness) -> fn(I) -> IResult where - I: Input, + I: Input, { match endian { crate::number::Endianness::Big => be_f32, @@ -1156,9 +1156,9 @@ where /// assert_eq!(le_f64(&b"abc"[..]), Err(Err::Error((&b"abc"[..], ErrorKind::Eof)))); /// ``` #[inline] -pub fn f64>(endian: crate::number::Endianness) -> fn(I) -> IResult +pub fn f64<'a, I, E: ParseError>(endian: crate::number::Endianness) -> fn(I) -> IResult where - I: Input, + I: Input, { match endian { crate::number::Endianness::Big => be_f64, @@ -1279,15 +1279,15 @@ where }) }, |i: T| { - crate::bytes::complete::tag_no_case::<_, _, E>("nan")(i.clone()) + crate::bytes::complete::tag_no_case::<_, _, E>("nan").parse(i.clone()) .map_err(|_| crate::Err::Error(E::from_error_kind(i, ErrorKind::Float))) }, |i: T| { - crate::bytes::complete::tag_no_case::<_, _, E>("infinity")(i.clone()) + crate::bytes::complete::tag_no_case::<_, _, E>("infinity").parse(i.clone()) .map_err(|_| crate::Err::Error(E::from_error_kind(i, ErrorKind::Float))) }, |i: T| { - crate::bytes::complete::tag_no_case::<_, _, E>("inf")(i.clone()) + crate::bytes::complete::tag_no_case::<_, _, E>("inf").parse(i.clone()) .map_err(|_| crate::Err::Error(E::from_error_kind(i, ErrorKind::Float))) }, )) diff --git a/src/number/mod.rs b/src/number/mod.rs index 9e7e3d7e8..2c5f945f5 100644 --- a/src/number/mod.rs +++ b/src/number/mod.rs @@ -34,9 +34,9 @@ pub enum Endianness { /// * `bound`: the number of bytes that will be read /// * `Uint`: the output type #[inline] -fn be_uint>(bound: usize) -> impl Parser +fn be_uint<'a, I, Uint, E: ParseError>(bound: usize) -> impl Parser where - I: Input, + I: Input, Uint: Default + Shl + Add + From, { BeUint { @@ -53,9 +53,9 @@ struct BeUint { u: PhantomData, } -impl> Parser for BeUint +impl<'a, I, Uint, E: ParseError> Parser for BeUint where - I: Input, + I: Input, Uint: Default + Shl + Add + From, { type Output = Uint; @@ -81,11 +81,11 @@ where // special case to avoid shift a byte with overflow if self.bound > 1 { for byte in input.iter_elements().take(self.bound) { - res = (res << 8) + byte.into(); + res = (res << 8) + (*byte).into(); } } else { for byte in input.iter_elements().take(self.bound) { - res = byte.into(); + res = (*byte).into(); } } @@ -111,9 +111,9 @@ where /// assert_eq!(parser(&b""[..]), Err(Err::Incomplete(Needed::new(1)))); /// ``` #[inline] -pub fn be_u8>() -> impl Parser +pub fn be_u8<'a, I, E: ParseError>() -> impl Parser where - I: Input, + I: Input, { be_uint(1) } @@ -132,9 +132,9 @@ where /// assert_eq!(parser(&b"\x01"[..]), Err(Err::Incomplete(Needed::new(1)))); /// ``` #[inline] -pub fn be_u16>() -> impl Parser +pub fn be_u16<'a, I, E: ParseError>() -> impl Parser where - I: Input, + I: Input, { be_uint(2) } @@ -153,9 +153,9 @@ where /// assert_eq!(parser(&b"\x01"[..]), Err(Err::Incomplete(Needed::new(2)))); /// ``` #[inline] -pub fn be_u24>() -> impl Parser +pub fn be_u24<'a, I, E: ParseError>() -> impl Parser where - I: Input, + I: Input, { be_uint(3) } @@ -174,9 +174,9 @@ where /// assert_eq!(parser(&b"\x01"[..]), Err(Err::Incomplete(Needed::new(3)))); /// ``` #[inline] -pub fn be_u32>() -> impl Parser +pub fn be_u32<'a, I, E: ParseError>() -> impl Parser where - I: Input, + I: Input, { be_uint(4) } @@ -195,9 +195,9 @@ where /// assert_eq!(parser(&b"\x01"[..]), Err(Err::Incomplete(Needed::new(7)))); /// ``` #[inline] -pub fn be_u64>() -> impl Parser +pub fn be_u64<'a, I, E: ParseError>() -> impl Parser where - I: Input, + I: Input, { be_uint(8) } @@ -216,9 +216,9 @@ where /// assert_eq!(parser(&b"\x01"[..]), Err(Err::Incomplete(Needed::new(15)))); /// ``` #[inline] -pub fn be_u128>() -> impl Parser +pub fn be_u128<'a, I, E: ParseError>() -> impl Parser where - I: Input, + I: Input, { be_uint(16) } @@ -236,9 +236,9 @@ where /// assert_eq!(parser.parse(&b""[..]), Err(Err::Incomplete(Needed::new(1)))); /// ``` #[inline] -pub fn be_i8>() -> impl Parser +pub fn be_i8<'a, I, E: ParseError>() -> impl Parser where - I: Input, + I: Input, { be_u8().map(|x| x as i8) } @@ -255,9 +255,9 @@ where /// assert_eq!(parser.parse(&b""[..]), Err(Err::Incomplete(Needed::new(2)))); /// ``` #[inline] -pub fn be_i16>() -> impl Parser +pub fn be_i16<'a, I, E: ParseError>() -> impl Parser where - I: Input, + I: Input, { be_u16().map(|x| x as i16) } @@ -274,9 +274,9 @@ where /// assert_eq!(parser.parse(&b""[..]), Err(Err::Incomplete(Needed::new(3)))); /// ``` #[inline] -pub fn be_i24>() -> impl Parser +pub fn be_i24<'a, I, E: ParseError>() -> impl Parser where - I: Input, + I: Input, { // Same as the unsigned version but we need to sign-extend manually here be_u24().map(|x| { @@ -300,9 +300,9 @@ where /// assert_eq!(parser.parse(&b""[..]), Err(Err::Incomplete(Needed::new(4)))); /// ``` #[inline] -pub fn be_i32>() -> impl Parser +pub fn be_i32<'a, I, E: ParseError>() -> impl Parser where - I: Input, + I: Input, { be_u32().map(|x| x as i32) } @@ -319,9 +319,9 @@ where /// assert_eq!(parser.parse(&b"\x01"[..]), Err(Err::Incomplete(Needed::new(7)))); /// ``` #[inline] -pub fn be_i64>() -> impl Parser +pub fn be_i64<'a, I, E: ParseError>() -> impl Parser where - I: Input, + I: Input, { be_u64().map(|x| x as i64) } @@ -338,9 +338,9 @@ where /// assert_eq!(parser.parse(&b"\x01"[..]), Err(Err::Incomplete(Needed::new(15)))); /// ``` #[inline] -pub fn be_i128>() -> impl Parser +pub fn be_i128<'a, I, E: ParseError>() -> impl Parser where - I: Input, + I: Input, { be_u128().map(|x| x as i128) } @@ -350,9 +350,9 @@ where /// * `bound`: the number of bytes that will be read /// * `Uint`: the output type #[inline] -fn le_uint>(bound: usize) -> impl Parser +fn le_uint<'a, I, Uint, E: ParseError>(bound: usize) -> impl Parser where - I: Input, + I: Input, Uint: Default + Shl + Add + From, { LeUint { @@ -369,9 +369,9 @@ struct LeUint { u: PhantomData, } -impl> Parser for LeUint +impl<'a, I, Uint, E: ParseError> Parser for LeUint where - I: Input, + I: Input, Uint: Default + Shl + Add + From, { type Output = Uint; @@ -394,7 +394,7 @@ where let res = OM::Output::bind(|| { let mut res = Uint::default(); for (index, byte) in input.iter_elements().take(self.bound).enumerate() { - res = res + (Uint::from(byte) << (8 * index as u8)); + res = res + (Uint::from(*byte) << (8 * index as u8)); } res @@ -417,9 +417,9 @@ where /// assert_eq!(parser.parse(&b""[..]), Err(Err::Incomplete(Needed::new(1)))); /// ``` #[inline] -pub fn le_u8>() -> impl Parser +pub fn le_u8<'a, I, E: ParseError>() -> impl Parser where - I: Input, + I: Input, { le_uint(1) } @@ -439,9 +439,9 @@ where /// assert_eq!(parser(&b"\x01"[..]), Err(Err::Incomplete(Needed::new(1)))); /// ``` #[inline] -pub fn le_u16>() -> impl Parser +pub fn le_u16<'a, I, E: ParseError>() -> impl Parser where - I: Input, + I: Input, { le_uint(2) } @@ -460,9 +460,9 @@ where /// assert_eq!(parser(&b"\x01"[..]), Err(Err::Incomplete(Needed::new(2)))); /// ``` #[inline] -pub fn le_u24>() -> impl Parser +pub fn le_u24<'a, I, E: ParseError>() -> impl Parser where - I: Input, + I: Input, { le_uint(3) } @@ -481,9 +481,9 @@ where /// assert_eq!(parser(&b"\x01"[..]), Err(Err::Incomplete(Needed::new(3)))); /// ``` #[inline] -pub fn le_u32>() -> impl Parser +pub fn le_u32<'a, I, E: ParseError>() -> impl Parser where - I: Input, + I: Input, { le_uint(4) } @@ -502,9 +502,9 @@ where /// assert_eq!(parser(&b"\x01"[..]), Err(Err::Incomplete(Needed::new(7)))); /// ``` #[inline] -pub fn le_u64>() -> impl Parser +pub fn le_u64<'a, I, E: ParseError>() -> impl Parser where - I: Input, + I: Input, { le_uint(8) } @@ -523,9 +523,9 @@ where /// assert_eq!(parser(&b"\x01"[..]), Err(Err::Incomplete(Needed::new(15)))); /// ``` #[inline] -pub fn le_u128>() -> impl Parser +pub fn le_u128<'a, I, E: ParseError>() -> impl Parser where - I: Input, + I: Input, { le_uint(16) } @@ -542,9 +542,9 @@ where /// assert_eq!(parser.parse(&b""[..]), Err(Err::Incomplete(Needed::new(1)))); /// ``` #[inline] -pub fn le_i8>() -> impl Parser +pub fn le_i8<'a, I, E: ParseError>() -> impl Parser where - I: Input, + I: Input, { le_u8().map(|x| x as i8) } @@ -563,9 +563,9 @@ where /// assert_eq!(parser(&b"\x01"[..]), Err(Err::Incomplete(Needed::new(1)))); /// ``` #[inline] -pub fn le_i16>() -> impl Parser +pub fn le_i16<'a, I, E: ParseError>() -> impl Parser where - I: Input, + I: Input, { le_u16().map(|x| x as i16) } @@ -584,9 +584,9 @@ where /// assert_eq!(parser(&b"\x01"[..]), Err(Err::Incomplete(Needed::new(2)))); /// ``` #[inline] -pub fn le_i24>() -> impl Parser +pub fn le_i24<'a, I, E: ParseError>() -> impl Parser where - I: Input, + I: Input, { // Same as the unsigned version but we need to sign-extend manually here le_u24().map(|x| { @@ -612,9 +612,9 @@ where /// assert_eq!(parser(&b"\x01"[..]), Err(Err::Incomplete(Needed::new(3)))); /// ``` #[inline] -pub fn le_i32>() -> impl Parser +pub fn le_i32<'a, I, E: ParseError>() -> impl Parser where - I: Input, + I: Input, { le_u32().map(|x| x as i32) } @@ -633,9 +633,9 @@ where /// assert_eq!(parser(&b"\x01"[..]), Err(Err::Incomplete(Needed::new(7)))); /// ``` #[inline] -pub fn le_i64>() -> impl Parser +pub fn le_i64<'a, I, E: ParseError>() -> impl Parser where - I: Input, + I: Input, { le_u64().map(|x| x as i64) } @@ -654,9 +654,9 @@ where /// assert_eq!(parser(&b"\x01"[..]), Err(Err::Incomplete(Needed::new(15)))); /// ``` #[inline] -pub fn le_i128>() -> impl Parser +pub fn le_i128<'a, I, E: ParseError>() -> impl Parser where - I: Input, + I: Input, { le_u128().map(|x| x as i128) } @@ -677,9 +677,9 @@ where /// assert_eq!(parser(&b""[..]), Err(Err::Incomplete(Needed::new(1)))); /// ``` #[inline] -pub fn u8>() -> impl Parser +pub fn u8<'a, I, E: ParseError>() -> impl Parser where - I: Input, + I: Input, { be_u8() } @@ -709,11 +709,11 @@ where /// assert_eq!(le_u16(&b"\x01"[..]), Err(Err::Incomplete(Needed::new(1)))); /// ``` #[inline] -pub fn u16>( +pub fn u16<'a, I, E: ParseError>( endian: crate::number::Endianness, ) -> impl Parser where - I: Input, + I: Input, { match endian { crate::number::Endianness::Big => Either::Left(be_u16()), @@ -749,11 +749,11 @@ where /// assert_eq!(le_u24(&b"\x01"[..]), Err(Err::Incomplete(Needed::new(2)))); /// ``` #[inline] -pub fn u24>( +pub fn u24<'a, I, E: ParseError>( endian: crate::number::Endianness, ) -> impl Parser where - I: Input, + I: Input, { match endian { crate::number::Endianness::Big => Either::Left(be_u24()), @@ -789,11 +789,11 @@ where /// assert_eq!(le_u32(&b"\x01"[..]), Err(Err::Incomplete(Needed::new(3)))); /// ``` #[inline] -pub fn u32>( +pub fn u32<'a, I, E: ParseError>( endian: crate::number::Endianness, ) -> impl Parser where - I: Input, + I: Input, { match endian { crate::number::Endianness::Big => Either::Left(be_u32()), @@ -829,11 +829,11 @@ where /// assert_eq!(le_u64(&b"\x01"[..]), Err(Err::Incomplete(Needed::new(7)))); /// ``` #[inline] -pub fn u64>( +pub fn u64<'a, I, E: ParseError>( endian: crate::number::Endianness, ) -> impl Parser where - I: Input, + I: Input, { match endian { crate::number::Endianness::Big => Either::Left(be_u64()), @@ -869,11 +869,11 @@ where /// assert_eq!(le_u128(&b"\x01"[..]), Err(Err::Incomplete(Needed::new(15)))); /// ``` #[inline] -pub fn u128>( +pub fn u128<'a, I, E: ParseError>( endian: crate::number::Endianness, ) -> impl Parser where - I: Input, + I: Input, { match endian { crate::number::Endianness::Big => Either::Left(be_u128()), @@ -902,9 +902,9 @@ where /// assert_eq!(parser(&b""[..]), Err(Err::Incomplete(Needed::new(1)))); /// ``` #[inline] -pub fn i8>() -> impl Parser +pub fn i8<'a, I, E: ParseError>() -> impl Parser where - I: Input, + I: Input, { u8().map(|x| x as i8) } @@ -934,11 +934,11 @@ where /// assert_eq!(le_i16(&b"\x01"[..]), Err(Err::Incomplete(Needed::new(1)))); /// ``` #[inline] -pub fn i16>( +pub fn i16<'a, I, E: ParseError>( endian: crate::number::Endianness, ) -> impl Parser where - I: Input, + I: Input, { match endian { crate::number::Endianness::Big => Either::Left(be_i16()), @@ -975,11 +975,11 @@ where /// assert_eq!(le_i24(&b"\x01"[..]), Err(Err::Incomplete(Needed::new(2)))); /// ``` #[inline] -pub fn i24>( +pub fn i24<'a, I, E: ParseError>( endian: crate::number::Endianness, ) -> impl Parser where - I: Input, + I: Input, { match endian { crate::number::Endianness::Big => Either::Left(be_i24()), @@ -1016,11 +1016,11 @@ where /// assert_eq!(le_i32(&b"\x01"[..]), Err(Err::Incomplete(Needed::new(3)))); /// ``` #[inline] -pub fn i32>( +pub fn i32<'a, I, E: ParseError>( endian: crate::number::Endianness, ) -> impl Parser where - I: Input, + I: Input, { match endian { crate::number::Endianness::Big => Either::Left(be_i32()), @@ -1057,11 +1057,11 @@ where /// assert_eq!(le_i64(&b"\x01"[..]), Err(Err::Incomplete(Needed::new(7)))); /// ``` #[inline] -pub fn i64>( +pub fn i64<'a, I, E: ParseError>( endian: crate::number::Endianness, ) -> impl Parser where - I: Input, + I: Input, { match endian { crate::number::Endianness::Big => Either::Left(be_i64()), @@ -1098,11 +1098,11 @@ where /// assert_eq!(le_i128(&b"\x01"[..]), Err(Err::Incomplete(Needed::new(15)))); /// ``` #[inline] -pub fn i128>( +pub fn i128<'a, I, E: ParseError>( endian: crate::number::Endianness, ) -> impl Parser where - I: Input, + I: Input, { match endian { crate::number::Endianness::Big => Either::Left(be_i128()), @@ -1129,9 +1129,9 @@ where /// assert_eq!(parser(&[0x01][..]), Err(Err::Incomplete(Needed::new(3)))); /// ``` #[inline] -pub fn be_f32>() -> impl Parser +pub fn be_f32<'a, I, E: ParseError>() -> impl Parser where - I: Input, + I: Input, { be_u32().map(f32::from_bits) } @@ -1151,9 +1151,9 @@ where /// assert_eq!(parser(&[0x01][..]), Err(Err::Incomplete(Needed::new(7)))); /// ``` #[inline] -pub fn be_f64>() -> impl Parser +pub fn be_f64<'a, I, E: ParseError>() -> impl Parser where - I: Input, + I: Input, { be_u64().map(f64::from_bits) } @@ -1173,9 +1173,9 @@ where /// assert_eq!(parser(&[0x01][..]), Err(Err::Incomplete(Needed::new(3)))); /// ``` #[inline] -pub fn le_f32>() -> impl Parser +pub fn le_f32<'a, I, E: ParseError>() -> impl Parser where - I: Input, + I: Input, { le_u32().map(f32::from_bits) } @@ -1195,9 +1195,9 @@ where /// assert_eq!(parser(&[0x01][..]), Err(Err::Incomplete(Needed::new(7)))); /// ``` #[inline] -pub fn le_f64>() -> impl Parser +pub fn le_f64<'a, I, E: ParseError>() -> impl Parser where - I: Input, + I: Input, { le_u64().map(f64::from_bits) } @@ -1227,11 +1227,11 @@ where /// assert_eq!(le_f32(&b"abc"[..]), Err(Err::Incomplete(Needed::new(1)))); /// ``` #[inline] -pub fn f32>( +pub fn f32<'a, I, E: ParseError>( endian: crate::number::Endianness, ) -> impl Parser where - I: Input, + I: Input, { match endian { crate::number::Endianness::Big => Either::Left(be_f32()), @@ -1268,11 +1268,11 @@ where /// assert_eq!(le_f64(&b"abc"[..]), Err(Err::Incomplete(Needed::new(5)))); /// ``` #[inline] -pub fn f64>( +pub fn f64<'a, I, E: ParseError>( endian: crate::number::Endianness, ) -> impl Parser where - I: Input, + I: Input, { match endian { crate::number::Endianness::Big => Either::Left(be_f64()), diff --git a/src/number/streaming.rs b/src/number/streaming.rs index cd892d657..b3f4f1ecc 100644 --- a/src/number/streaming.rs +++ b/src/number/streaming.rs @@ -25,9 +25,9 @@ use crate::{internal::*, Input}; /// assert_eq!(parser(&b""[..]), Err(Err::Incomplete(Needed::new(1)))); /// ``` #[inline] -pub fn be_u8>(input: I) -> IResult +pub fn be_u8<'a, I, E: ParseError>(input: I) -> IResult where - I: Input, + I: Input, { be_uint(input, 1) } @@ -48,9 +48,9 @@ where /// assert_eq!(parser(&b"\x01"[..]), Err(Err::Incomplete(Needed::new(1)))); /// ``` #[inline] -pub fn be_u16>(input: I) -> IResult +pub fn be_u16<'a, I, E: ParseError>(input: I) -> IResult where - I: Input, + I: Input, { be_uint(input, 2) } @@ -71,9 +71,9 @@ where /// assert_eq!(parser(&b"\x01"[..]), Err(Err::Incomplete(Needed::new(2)))); /// ``` #[inline] -pub fn be_u24>(input: I) -> IResult +pub fn be_u24<'a, I, E: ParseError>(input: I) -> IResult where - I: Input, + I: Input, { be_uint(input, 3) } @@ -94,9 +94,9 @@ where /// assert_eq!(parser(&b"\x01"[..]), Err(Err::Incomplete(Needed::new(3)))); /// ``` #[inline] -pub fn be_u32>(input: I) -> IResult +pub fn be_u32<'a, I, E: ParseError>(input: I) -> IResult where - I: Input, + I: Input, { be_uint(input, 4) } @@ -117,9 +117,9 @@ where /// assert_eq!(parser(&b"\x01"[..]), Err(Err::Incomplete(Needed::new(7)))); /// ``` #[inline] -pub fn be_u64>(input: I) -> IResult +pub fn be_u64<'a, I, E: ParseError>(input: I) -> IResult where - I: Input, + I: Input, { be_uint(input, 8) } @@ -139,17 +139,17 @@ where /// assert_eq!(parser(&b"\x01"[..]), Err(Err::Incomplete(Needed::new(15)))); /// ``` #[inline] -pub fn be_u128>(input: I) -> IResult +pub fn be_u128<'a, I, E: ParseError>(input: I) -> IResult where - I: Input, + I: Input, { be_uint(input, 16) } #[inline] -fn be_uint>(input: I, bound: usize) -> IResult +fn be_uint<'a, I, Uint, E: ParseError>(input: I, bound: usize) -> IResult where - I: Input, + I: Input, Uint: Default + Shl + Add + From, { super::be_uint(bound).parse(input) @@ -168,9 +168,9 @@ where /// assert_eq!(parser(&b""[..]), Err(Err::Incomplete(Needed::new(1)))); /// ``` #[inline] -pub fn be_i8>(input: I) -> IResult +pub fn be_i8<'a, I, E: ParseError>(input: I) -> IResult where - I: Input, + I: Input, { be_u8.map(|x| x as i8).parse(input) } @@ -188,9 +188,9 @@ where /// assert_eq!(parser(&b""[..]), Err(Err::Incomplete(Needed::new(2)))); /// ``` #[inline] -pub fn be_i16>(input: I) -> IResult +pub fn be_i16<'a, I, E: ParseError>(input: I) -> IResult where - I: Input, + I: Input, { be_u16.map(|x| x as i16).parse(input) } @@ -208,9 +208,9 @@ where /// assert_eq!(parser(&b""[..]), Err(Err::Incomplete(Needed::new(3)))); /// ``` #[inline] -pub fn be_i24>(input: I) -> IResult +pub fn be_i24<'a, I, E: ParseError>(input: I) -> IResult where - I: Input, + I: Input, { // Same as the unsigned version but we need to sign-extend manually here be_u24 @@ -237,9 +237,9 @@ where /// assert_eq!(parser(&b""[..]), Err(Err::Incomplete(Needed::new(4)))); /// ``` #[inline] -pub fn be_i32>(input: I) -> IResult +pub fn be_i32<'a, I, E: ParseError>(input: I) -> IResult where - I: Input, + I: Input, { be_u32.map(|x| x as i32).parse(input) } @@ -258,9 +258,9 @@ where /// assert_eq!(parser(&b"\x01"[..]), Err(Err::Incomplete(Needed::new(7)))); /// ``` #[inline] -pub fn be_i64>(input: I) -> IResult +pub fn be_i64<'a, I, E: ParseError>(input: I) -> IResult where - I: Input, + I: Input, { be_u64.map(|x| x as i64).parse(input) } @@ -278,9 +278,9 @@ where /// assert_eq!(parser(&b"\x01"[..]), Err(Err::Incomplete(Needed::new(15)))); /// ``` #[inline] -pub fn be_i128>(input: I) -> IResult +pub fn be_i128<'a, I, E: ParseError>(input: I) -> IResult where - I: Input, + I: Input, { be_u128.map(|x| x as i128).parse(input) } @@ -298,9 +298,9 @@ where /// assert_eq!(parser(&b""[..]), Err(Err::Incomplete(Needed::new(1)))); /// ``` #[inline] -pub fn le_u8>(input: I) -> IResult +pub fn le_u8<'a, I, E: ParseError>(input: I) -> IResult where - I: Input, + I: Input, { le_uint(input, 1) } @@ -321,9 +321,9 @@ where /// assert_eq!(parser(&b"\x01"[..]), Err(Err::Incomplete(Needed::new(1)))); /// ``` #[inline] -pub fn le_u16>(input: I) -> IResult +pub fn le_u16<'a, I, E: ParseError>(input: I) -> IResult where - I: Input, + I: Input, { le_uint(input, 2) } @@ -344,9 +344,9 @@ where /// assert_eq!(parser(&b"\x01"[..]), Err(Err::Incomplete(Needed::new(2)))); /// ``` #[inline] -pub fn le_u24>(input: I) -> IResult +pub fn le_u24<'a, I, E: ParseError>(input: I) -> IResult where - I: Input, + I: Input, { le_uint(input, 3) } @@ -367,9 +367,9 @@ where /// assert_eq!(parser(&b"\x01"[..]), Err(Err::Incomplete(Needed::new(3)))); /// ``` #[inline] -pub fn le_u32>(input: I) -> IResult +pub fn le_u32<'a, I, E: ParseError>(input: I) -> IResult where - I: Input, + I: Input, { le_uint(input, 4) } @@ -390,9 +390,9 @@ where /// assert_eq!(parser(&b"\x01"[..]), Err(Err::Incomplete(Needed::new(7)))); /// ``` #[inline] -pub fn le_u64>(input: I) -> IResult +pub fn le_u64<'a, I, E: ParseError>(input: I) -> IResult where - I: Input, + I: Input, { le_uint(input, 8) } @@ -413,17 +413,17 @@ where /// assert_eq!(parser(&b"\x01"[..]), Err(Err::Incomplete(Needed::new(15)))); /// ``` #[inline] -pub fn le_u128>(input: I) -> IResult +pub fn le_u128<'a, I, E: ParseError>(input: I) -> IResult where - I: Input, + I: Input, { le_uint(input, 16) } #[inline] -fn le_uint>(input: I, bound: usize) -> IResult +fn le_uint<'a, I, Uint, E: ParseError>(input: I, bound: usize) -> IResult where - I: Input, + I: Input, Uint: Default + Shl + Add + From, { super::le_uint(bound).parse(input) @@ -442,9 +442,9 @@ where /// assert_eq!(parser(&b""[..]), Err(Err::Incomplete(Needed::new(1)))); /// ``` #[inline] -pub fn le_i8>(input: I) -> IResult +pub fn le_i8<'a, I, E: ParseError>(input: I) -> IResult where - I: Input, + I: Input, { le_u8.map(|x| x as i8).parse(input) } @@ -465,9 +465,9 @@ where /// assert_eq!(parser(&b"\x01"[..]), Err(Err::Incomplete(Needed::new(1)))); /// ``` #[inline] -pub fn le_i16>(input: I) -> IResult +pub fn le_i16<'a, I, E: ParseError>(input: I) -> IResult where - I: Input, + I: Input, { le_u16.map(|x| x as i16).parse(input) } @@ -488,9 +488,9 @@ where /// assert_eq!(parser(&b"\x01"[..]), Err(Err::Incomplete(Needed::new(2)))); /// ``` #[inline] -pub fn le_i24>(input: I) -> IResult +pub fn le_i24<'a, I, E: ParseError>(input: I) -> IResult where - I: Input, + I: Input, { // Same as the unsigned version but we need to sign-extend manually here le_u24 @@ -520,9 +520,9 @@ where /// assert_eq!(parser(&b"\x01"[..]), Err(Err::Incomplete(Needed::new(3)))); /// ``` #[inline] -pub fn le_i32>(input: I) -> IResult +pub fn le_i32<'a, I, E: ParseError>(input: I) -> IResult where - I: Input, + I: Input, { le_u32.map(|x| x as i32).parse(input) } @@ -543,9 +543,9 @@ where /// assert_eq!(parser(&b"\x01"[..]), Err(Err::Incomplete(Needed::new(7)))); /// ``` #[inline] -pub fn le_i64>(input: I) -> IResult +pub fn le_i64<'a, I, E: ParseError>(input: I) -> IResult where - I: Input, + I: Input, { le_u64.map(|x| x as i64).parse(input) } @@ -566,9 +566,9 @@ where /// assert_eq!(parser(&b"\x01"[..]), Err(Err::Incomplete(Needed::new(15)))); /// ``` #[inline] -pub fn le_i128>(input: I) -> IResult +pub fn le_i128<'a, I, E: ParseError>(input: I) -> IResult where - I: Input, + I: Input, { le_u128.map(|x| x as i128).parse(input) } @@ -590,9 +590,9 @@ where /// assert_eq!(parser(&b""[..]), Err(Err::Incomplete(Needed::new(1)))); /// ``` #[inline] -pub fn u8>(input: I) -> IResult +pub fn u8<'a, I, E: ParseError>(input: I) -> IResult where - I: Input, + I: Input, { super::u8().parse(input) } @@ -623,11 +623,11 @@ where /// assert_eq!(le_u16(&b"\x01"[..]), Err(Err::Incomplete(Needed::new(1)))); /// ``` #[inline] -pub fn u16>( +pub fn u16<'a, I, E: ParseError>( endian: crate::number::Endianness, ) -> impl Fn(I) -> IResult where - I: Input, + I: Input, { move |input| super::u16(endian).parse(input) } @@ -657,11 +657,11 @@ where /// assert_eq!(le_u24(&b"\x01"[..]), Err(Err::Incomplete(Needed::new(2)))); /// ``` #[inline] -pub fn u24>( +pub fn u24<'a, I, E: ParseError>( endian: crate::number::Endianness, ) -> impl Fn(I) -> IResult where - I: Input, + I: Input, { move |input| super::u24(endian).parse(input) } @@ -691,11 +691,11 @@ where /// assert_eq!(le_u32(&b"\x01"[..]), Err(Err::Incomplete(Needed::new(3)))); /// ``` #[inline] -pub fn u32>( +pub fn u32<'a, I, E: ParseError>( endian: crate::number::Endianness, ) -> impl Fn(I) -> IResult where - I: Input, + I: Input, { move |input| super::u32(endian).parse(input) } @@ -725,11 +725,11 @@ where /// assert_eq!(le_u64(&b"\x01"[..]), Err(Err::Incomplete(Needed::new(7)))); /// ``` #[inline] -pub fn u64>( +pub fn u64<'a, I, E: ParseError>( endian: crate::number::Endianness, ) -> impl Fn(I) -> IResult where - I: Input, + I: Input, { move |input| super::u64(endian).parse(input) } @@ -759,11 +759,11 @@ where /// assert_eq!(le_u128(&b"\x01"[..]), Err(Err::Incomplete(Needed::new(15)))); /// ``` #[inline] -pub fn u128>( +pub fn u128<'a, I, E: ParseError>( endian: crate::number::Endianness, ) -> impl Fn(I) -> IResult where - I: Input, + I: Input, { move |input| super::u128(endian).parse(input) } @@ -785,9 +785,9 @@ where /// assert_eq!(parser(&b""[..]), Err(Err::Incomplete(Needed::new(1)))); /// ``` #[inline] -pub fn i8>(i: I) -> IResult +pub fn i8<'a, I, E: ParseError>(i: I) -> IResult where - I: Input, + I: Input, { super::u8().map(|x| x as i8).parse(i) } @@ -817,11 +817,11 @@ where /// assert_eq!(le_i16(&b"\x01"[..]), Err(Err::Incomplete(Needed::new(1)))); /// ``` #[inline] -pub fn i16>( +pub fn i16<'a, I, E: ParseError>( endian: crate::number::Endianness, ) -> impl Fn(I) -> IResult where - I: Input, + I: Input, { move |input| super::i16(endian).parse(input) } @@ -851,11 +851,11 @@ where /// assert_eq!(le_i24(&b"\x01"[..]), Err(Err::Incomplete(Needed::new(2)))); /// ``` #[inline] -pub fn i24>( +pub fn i24<'a, I, E: ParseError>( endian: crate::number::Endianness, ) -> impl Fn(I) -> IResult where - I: Input, + I: Input, { move |input| super::i24(endian).parse(input) } @@ -885,11 +885,11 @@ where /// assert_eq!(le_i32(&b"\x01"[..]), Err(Err::Incomplete(Needed::new(3)))); /// ``` #[inline] -pub fn i32>( +pub fn i32<'a, I, E: ParseError>( endian: crate::number::Endianness, ) -> impl Fn(I) -> IResult where - I: Input, + I: Input, { move |input| super::i32(endian).parse(input) } @@ -919,11 +919,11 @@ where /// assert_eq!(le_i64(&b"\x01"[..]), Err(Err::Incomplete(Needed::new(7)))); /// ``` #[inline] -pub fn i64>( +pub fn i64<'a, I, E: ParseError>( endian: crate::number::Endianness, ) -> impl Fn(I) -> IResult where - I: Input, + I: Input, { move |input| super::i64(endian).parse(input) } @@ -953,11 +953,11 @@ where /// assert_eq!(le_i128(&b"\x01"[..]), Err(Err::Incomplete(Needed::new(15)))); /// ``` #[inline] -pub fn i128>( +pub fn i128<'a, I, E: ParseError>( endian: crate::number::Endianness, ) -> impl Fn(I) -> IResult where - I: Input, + I: Input, { move |input| super::i128(endian).parse(input) } @@ -977,9 +977,9 @@ where /// assert_eq!(parser(&[0x01][..]), Err(Err::Incomplete(Needed::new(3)))); /// ``` #[inline] -pub fn be_f32>(input: I) -> IResult +pub fn be_f32<'a, I, E: ParseError>(input: I) -> IResult where - I: Input, + I: Input, { match be_u32(input) { Err(e) => Err(e), @@ -1002,9 +1002,9 @@ where /// assert_eq!(parser(&[0x01][..]), Err(Err::Incomplete(Needed::new(7)))); /// ``` #[inline] -pub fn be_f64>(input: I) -> IResult +pub fn be_f64<'a, I, E: ParseError>(input: I) -> IResult where - I: Input, + I: Input, { match be_u64(input) { Err(e) => Err(e), @@ -1027,9 +1027,9 @@ where /// assert_eq!(parser(&[0x01][..]), Err(Err::Incomplete(Needed::new(3)))); /// ``` #[inline] -pub fn le_f32>(input: I) -> IResult +pub fn le_f32<'a, I, E: ParseError>(input: I) -> IResult where - I: Input, + I: Input, { match le_u32(input) { Err(e) => Err(e), @@ -1052,9 +1052,9 @@ where /// assert_eq!(parser(&[0x01][..]), Err(Err::Incomplete(Needed::new(7)))); /// ``` #[inline] -pub fn le_f64>(input: I) -> IResult +pub fn le_f64<'a, I, E: ParseError>(input: I) -> IResult where - I: Input, + I: Input, { match le_u64(input) { Err(e) => Err(e), @@ -1087,9 +1087,9 @@ where /// assert_eq!(le_f32(&b"abc"[..]), Err(Err::Incomplete(Needed::new(1)))); /// ``` #[inline] -pub fn f32>(endian: crate::number::Endianness) -> fn(I) -> IResult +pub fn f32<'a, I, E: ParseError>(endian: crate::number::Endianness) -> fn(I) -> IResult where - I: Input, + I: Input, { match endian { crate::number::Endianness::Big => be_f32, @@ -1126,9 +1126,9 @@ where /// assert_eq!(le_f64(&b"abc"[..]), Err(Err::Incomplete(Needed::new(5)))); /// ``` #[inline] -pub fn f64>(endian: crate::number::Endianness) -> fn(I) -> IResult +pub fn f64<'a, I, E: ParseError>(endian: crate::number::Endianness) -> fn(I) -> IResult where - I: Input, + I: Input, { match endian { crate::number::Endianness::Big => be_f64, diff --git a/src/traits.rs b/src/traits.rs index f778c3601..a2d04996b 100644 --- a/src/traits.rs +++ b/src/traits.rs @@ -4,7 +4,6 @@ use core::str::CharIndices; use crate::error::{ErrorKind, ParseError}; use crate::internal::{Err, IResult, Needed}; -use crate::lib::std::iter::Copied; use crate::lib::std::ops::{ Bound, Range, RangeBounds, RangeFrom, RangeFull, RangeInclusive, RangeTo, RangeToInclusive, }; @@ -190,9 +189,9 @@ pub trait Input: Clone + Sized { } } -impl<'a> Input for &'a [u8] { - type Item = u8; - type Iter = Copied>; +impl<'a, T> Input for &'a [T] { + type Item = &'a T; + type Iter = Iter<'a, T>; type IterIndices = Enumerate; fn input_len(&self) -> usize { @@ -218,12 +217,12 @@ impl<'a> Input for &'a [u8] { where P: Fn(Self::Item) -> bool, { - self.iter().position(|b| predicate(*b)) + self.iter().position(|b| predicate(b)) } #[inline] fn iter_elements(&self) -> Self::Iter { - self.iter().copied() + self.iter() } #[inline] @@ -245,7 +244,7 @@ impl<'a> Input for &'a [u8] { where P: Fn(Self::Item) -> bool, { - match self.iter().position(|c| predicate(*c)) { + match self.iter().position(|c| predicate(c)) { Some(i) => Ok(self.take_split(i)), None => Err(Err::Incomplete(Needed::new(1))), } @@ -260,7 +259,7 @@ impl<'a> Input for &'a [u8] { where P: Fn(Self::Item) -> bool, { - match self.iter().position(|c| predicate(*c)) { + match self.iter().position(|c| predicate(c)) { Some(0) => Err(Err::Error(E::from_error_kind(self, e))), Some(i) => Ok(self.take_split(i)), None => Err(Err::Incomplete(Needed::new(1))), @@ -274,7 +273,7 @@ impl<'a> Input for &'a [u8] { where P: Fn(Self::Item) -> bool, { - match self.iter().position(|c| predicate(*c)) { + match self.iter().position(|c| predicate(c)) { Some(i) => Ok(self.take_split(i)), None => Ok(self.take_split(self.len())), } @@ -289,7 +288,7 @@ impl<'a> Input for &'a [u8] { where P: Fn(Self::Item) -> bool, { - match self.iter().position(|c| predicate(*c)) { + match self.iter().position(|c| predicate(c)) { Some(0) => Err(Err::Error(E::from_error_kind(self, e))), Some(i) => Ok(self.take_split(i)), None => { @@ -311,7 +310,7 @@ impl<'a> Input for &'a [u8] { where P: Fn(Self::Item) -> bool, { - match self.iter().position(|c| predicate(*c)) { + match self.iter().position(|c| predicate(c)) { Some(n) => Ok((self.take_from(n), OM::Output::bind(|| self.take(n)))), None => { if OM::Incomplete::is_streaming() { @@ -336,7 +335,7 @@ impl<'a> Input for &'a [u8] { where P: Fn(Self::Item) -> bool, { - match self.iter().position(|c| predicate(*c)) { + match self.iter().position(|c| predicate(c)) { Some(0) => Err(Err::Error(OM::Error::bind(|| E::from_error_kind(self, e)))), Some(n) => Ok((self.take_from(n), OM::Output::bind(|| self.take(n)))), None => { @@ -565,6 +564,36 @@ impl<'a> Input for &'a str { } } +/// This trait is used to automatically convert types into the known Input types. +/// As an example, the generic implementation for const sized slices to normal slices is used. +/// You can also implement this on your own types, to make it easier to use in for example the `tag` function. +pub trait IntoInput { + /// The input type that this type can be converted into + type Input: Input; + + /// Converts this type into the input type + fn into_input(self) -> Self::Input; +} + +impl IntoInput for T { + type Input = T; + + fn into_input(self) -> Self::Input { + self + } +} + +impl<'a, T, const D: usize> IntoInput for &'a [T; D] +where + &'a [T]: Input, +{ + type Input = &'a [T]; + + fn into_input(self) -> Self::Input { + self.as_slice() + } +} + /// Useful functions to calculate the offset between slices and show a hexdump of a slice pub trait Offset { /// Offset between the first byte of self and the first byte of the argument @@ -573,7 +602,7 @@ pub trait Offset { fn offset(&self, second: &Self) -> usize; } -impl Offset for [u8] { +impl Offset for [T] { fn offset(&self, second: &Self) -> usize { let fst = self.as_ptr(); let snd = second.as_ptr(); @@ -582,7 +611,7 @@ impl Offset for [u8] { } } -impl<'a> Offset for &'a [u8] { +impl<'a, T> Offset for &'a [T] { fn offset(&self, second: &Self) -> usize { let fst = self.as_ptr(); let snd = second.as_ptr(); @@ -1165,16 +1194,16 @@ impl ExtendInto for [u8] { } #[cfg(feature = "alloc")] -impl ExtendInto for &[u8] { - type Item = u8; - type Extender = Vec; +impl ExtendInto for &[T] { + type Item = T; + type Extender = Vec; #[inline] - fn new_builder(&self) -> Vec { + fn new_builder(&self) -> Vec { Vec::new() } #[inline] - fn extend_into(&self, acc: &mut Vec) { + fn extend_into(&self, acc: &mut Vec) { acc.extend_from_slice(self); } } @@ -1678,4 +1707,15 @@ mod tests { assert!(a.slice_index(8).is_err()); } + + #[test] + fn test_const_slice_input() { + let a = b"abcdefg"; + let b = &a[2..]; + let c = &a[..4]; + let d = &a[3..5]; + assert_eq!(a.into_input().take_from(2), b); + assert_eq!(a.into_input().take(4), c); + assert_eq!(a.into_input().take_from(3).take(2), d); + } } diff --git a/tests/ini.rs b/tests/ini.rs index 2876fe7f2..52af4f72e 100644 --- a/tests/ini.rs +++ b/tests/ini.rs @@ -14,7 +14,7 @@ use std::str; fn category(i: &[u8]) -> IResult<&[u8], &str> { map_res( - delimited(char('['), take_while(|c| c != b']'), char(']')), + delimited(char('['), take_while(|&c| c != b']'), char(']')), str::from_utf8, ) .parse(i) @@ -23,8 +23,8 @@ fn category(i: &[u8]) -> IResult<&[u8], &str> { fn key_value(i: &[u8]) -> IResult<&[u8], (&str, &str)> { let (i, key) = map_res(alphanumeric, str::from_utf8).parse(i)?; let (i, _) = (opt(space), char('='), opt(space)).parse(i)?; - let (i, val) = map_res(take_while(|c| c != b'\n' && c != b';'), str::from_utf8).parse(i)?; - let (i, _) = opt(pair(char(';'), take_while(|c| c != b'\n'))).parse(i)?; + let (i, val) = map_res(take_while(|&c| c != b'\n' && c != b';'), str::from_utf8).parse(i)?; + let (i, _) = opt(pair(char(';'), take_while(|&c| c != b'\n'))).parse(i)?; Ok((i, (key, val))) } From b50848760bf6d0212780fc535bb5f1a3a53d20a7 Mon Sep 17 00:00:00 2001 From: Marc de Jonge Date: Mon, 10 Feb 2025 16:08:58 +0100 Subject: [PATCH 2/3] Fix the benchmarks --- benchmarks/benches/http.rs | 24 ++++++++++++------------ benchmarks/benches/http_streaming.rs | 24 ++++++++++++------------ benchmarks/benches/ini.rs | 6 +++--- 3 files changed, 27 insertions(+), 27 deletions(-) diff --git a/benchmarks/benches/http.rs b/benchmarks/benches/http.rs index 9ead6e546..47aa06b4e 100644 --- a/benchmarks/benches/http.rs +++ b/benchmarks/benches/http.rs @@ -22,8 +22,8 @@ struct Header<'a> { #[cfg_attr(rustfmt, rustfmt_skip)] #[cfg_attr(feature = "cargo-clippy", allow(match_same_arms))] -fn is_token(c: u8) -> bool { - match c { +fn is_token(c: &u8) -> bool { + match *c { 128..=255 => false, 0..=31 => false, b'(' => false, @@ -48,23 +48,23 @@ fn is_token(c: u8) -> bool { } } -fn not_line_ending(c: u8) -> bool { - c != b'\r' && c != b'\n' +fn not_line_ending(c: &u8) -> bool { + *c != b'\r' && *c != b'\n' } -fn is_space(c: u8) -> bool { - c == b' ' +fn is_space(c: &u8) -> bool { + *c == b' ' } -fn is_not_space(c: u8) -> bool { - c != b' ' +fn is_not_space(c: &u8) -> bool { + *c != b' ' } -fn is_horizontal_space(c: u8) -> bool { - c == b' ' || c == b'\t' +fn is_horizontal_space(c: &u8) -> bool { + *c == b' ' || *c == b'\t' } -fn is_version(c: u8) -> bool { - c >= b'0' && c <= b'9' || c == b'.' +fn is_version(c: &u8) -> bool { + *c >= b'0' && *c <= b'9' || *c == b'.' } fn line_ending<'a>()-> impl Parser<&'a[u8], Output=&'a[u8], Error=Error<&'a[u8]>> { diff --git a/benchmarks/benches/http_streaming.rs b/benchmarks/benches/http_streaming.rs index 031ffd49c..c54b5e3de 100644 --- a/benchmarks/benches/http_streaming.rs +++ b/benchmarks/benches/http_streaming.rs @@ -22,8 +22,8 @@ struct Header<'a> { #[cfg_attr(rustfmt, rustfmt_skip)] #[cfg_attr(feature = "cargo-clippy", allow(match_same_arms))] -fn is_token(c: u8) -> bool { - match c { +fn is_token(c: &u8) -> bool { + match *c { 128..=255 => false, 0..=31 => false, b'(' => false, @@ -48,23 +48,23 @@ fn is_token(c: u8) -> bool { } } -fn not_line_ending(c: u8) -> bool { - c != b'\r' && c != b'\n' +fn not_line_ending(c: &u8) -> bool { + *c != b'\r' && *c != b'\n' } -fn is_space(c: u8) -> bool { - c == b' ' +fn is_space(c: &u8) -> bool { + *c == b' ' } -fn is_not_space(c: u8) -> bool { - c != b' ' +fn is_not_space(c: &u8) -> bool { + *c != b' ' } -fn is_horizontal_space(c: u8) -> bool { - c == b' ' || c == b'\t' +fn is_horizontal_space(c: &u8) -> bool { + *c == b' ' || *c == b'\t' } -fn is_version(c: u8) -> bool { - c >= b'0' && c <= b'9' || c == b'.' +fn is_version(c: &u8) -> bool { + *c >= b'0' && *c <= b'9' || *c == b'.' } fn request_line(input: &[u8]) -> IResult<&[u8], Request<'_>> { diff --git a/benchmarks/benches/ini.rs b/benchmarks/benches/ini.rs index c14b9b040..d1e87f914 100644 --- a/benchmarks/benches/ini.rs +++ b/benchmarks/benches/ini.rs @@ -18,7 +18,7 @@ use std::str; fn category(i: &[u8]) -> IResult<&[u8], &str> { map_res( - delimited(char('['), take_while(|c| c != b']'), char(']')), + delimited(char('['), take_while(|c: &u8| *c != b']'), char(']')), str::from_utf8, ) .parse_complete(i) @@ -28,8 +28,8 @@ fn key_value(i: &[u8]) -> IResult<&[u8], (&str, &str)> { let (i, key) = map_res(alphanumeric, str::from_utf8).parse_complete(i)?; let (i, _) = tuple((opt(space), char('='), opt(space))).parse_complete(i)?; let (i, val) = - map_res(take_while(|c| c != b'\n' && c != b';'), str::from_utf8).parse_complete(i)?; - let (i, _) = opt(pair(char(';'), take_while(|c| c != b'\n'))).parse_complete(i)?; + map_res(take_while(|c: &u8| *c != b'\n' && *c != b';'), str::from_utf8).parse_complete(i)?; + let (i, _) = opt(pair(char(';'), take_while(|c: &u8| *c != b'\n'))).parse_complete(i)?; Ok((i, (key, val))) } From 765bfa853b281f706b64ca8bf1378610fc6a28b4 Mon Sep 17 00:00:00 2001 From: Marc de Jonge Date: Mon, 10 Feb 2025 16:13:32 +0100 Subject: [PATCH 3/3] Fix the fuzzer to use a new version of upload-artifact --- .github/workflows/cifuzz.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cifuzz.yml b/.github/workflows/cifuzz.yml index fd0f7f6e1..275183754 100644 --- a/.github/workflows/cifuzz.yml +++ b/.github/workflows/cifuzz.yml @@ -19,7 +19,7 @@ jobs: dry-run: false language: rust - name: Upload Crash - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 if: failure() && steps.build.outcome == 'success' with: name: artifacts