Skip to content

Commit

Permalink
Merge pull request #105 from epage/input2
Browse files Browse the repository at this point in the history
fix(input)!: Cleanup to prepare for trait merger
  • Loading branch information
epage authored Jan 30, 2023
2 parents 6191b4b + 4c145c9 commit 74948e5
Show file tree
Hide file tree
Showing 20 changed files with 2,506 additions and 2,707 deletions.
14 changes: 7 additions & 7 deletions src/bits/complete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#![allow(deprecated)]

use crate::error::{ErrorKind, ParseError};
use crate::input::{InputIter, InputLength, Slice, ToUsize};
use crate::input::{InputIter, Slice, SliceLen, ToUsize};
use crate::lib::std::ops::{AddAssign, Div, RangeFrom, Shl, Shr};
use crate::{Err, IResult};

Expand Down Expand Up @@ -39,7 +39,7 @@ pub fn take<I, O, C, E: ParseError<(I, usize)>>(
count: C,
) -> impl Fn((I, usize)) -> IResult<(I, usize), O, E>
where
I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + SliceLen,
C: ToUsize,
O: From<u8> + AddAssign + Shl<usize, Output = O> + Shr<usize, Output = O>,
{
Expand All @@ -52,14 +52,14 @@ pub(crate) fn take_internal<I, O, E: ParseError<(I, usize)>>(
count: usize,
) -> IResult<(I, usize), O, E>
where
I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + SliceLen,
O: From<u8> + AddAssign + Shl<usize, Output = O> + Shr<usize, Output = O>,
{
if count == 0 {
Ok(((input, bit_offset), 0u8.into()))
} else {
let cnt = (count + bit_offset).div(8);
if input.input_len() * 8 < count + bit_offset {
if input.slice_len() * 8 < count + bit_offset {
Err(Err::Error(E::from_error_kind(
(input, bit_offset),
ErrorKind::Eof,
Expand Down Expand Up @@ -104,7 +104,7 @@ pub fn tag<I, O, C, E: ParseError<(I, usize)>>(
count: C,
) -> impl Fn((I, usize)) -> IResult<(I, usize), O, E>
where
I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength + Clone,
I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + SliceLen + Clone,
C: ToUsize,
O: From<u8> + AddAssign + Shl<usize, Output = O> + Shr<usize, Output = O> + PartialEq,
{
Expand All @@ -118,7 +118,7 @@ pub(crate) fn tag_internal<I, O, E: ParseError<(I, usize)>>(
count: usize,
) -> IResult<(I, usize), O, E>
where
I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength + Clone,
I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + SliceLen + Clone,
O: From<u8> + AddAssign + Shl<usize, Output = O> + Shr<usize, Output = O> + PartialEq,
{
let inp = input.clone();
Expand Down Expand Up @@ -151,7 +151,7 @@ where
#[deprecated(since = "8.0.0", note = "Replaced with `winnow::bits::bool`")]
pub fn bool<I, E: ParseError<(I, usize)>>(input: (I, usize)) -> IResult<(I, usize), bool, E>
where
I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + SliceLen,
{
let (res, bit): (_, u32) = take(1usize)(input)?;
Ok((res, bit != 0))
Expand Down
13 changes: 5 additions & 8 deletions src/bits/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub mod streaming;
mod tests;

use crate::error::{ErrorConvert, ErrorKind, ParseError};
use crate::input::{InputIsStreaming, InputIter, InputLength, Slice, ToUsize};
use crate::input::{InputIsStreaming, InputIter, Slice, SliceLen, ToUsize};
use crate::lib::std::ops::{AddAssign, RangeFrom, Shl, Shr};
use crate::{Err, IResult, Needed, Parser};

Expand Down Expand Up @@ -139,7 +139,7 @@ pub fn take<I, O, C, E: ParseError<(I, usize)>, const STREAMING: bool>(
count: C,
) -> impl Fn((I, usize)) -> IResult<(I, usize), O, E>
where
I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength + InputIsStreaming<STREAMING>,
I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + SliceLen + InputIsStreaming<STREAMING>,
C: ToUsize,
O: From<u8> + AddAssign + Shl<usize, Output = O> + Shr<usize, Output = O>,
{
Expand Down Expand Up @@ -203,11 +203,8 @@ pub fn tag<I, O, C, E: ParseError<(I, usize)>, const STREAMING: bool>(
count: C,
) -> impl Fn((I, usize)) -> IResult<(I, usize), O, E>
where
I: Slice<RangeFrom<usize>>
+ InputIter<Item = u8>
+ InputLength
+ InputIsStreaming<STREAMING>
+ Clone,
I:
Slice<RangeFrom<usize>> + InputIter<Item = u8> + SliceLen + InputIsStreaming<STREAMING> + Clone,
C: ToUsize,
O: From<u8> + AddAssign + Shl<usize, Output = O> + Shr<usize, Output = O> + PartialEq,
{
Expand Down Expand Up @@ -241,7 +238,7 @@ pub fn bool<I, E: ParseError<(I, usize)>, const STREAMING: bool>(
input: (I, usize),
) -> IResult<(I, usize), bool, E>
where
I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength + InputIsStreaming<STREAMING>,
I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + SliceLen + InputIsStreaming<STREAMING>,
{
#![allow(deprecated)]
if STREAMING {
Expand Down
14 changes: 7 additions & 7 deletions src/bits/streaming.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#![allow(deprecated)]

use crate::error::{ErrorKind, ParseError};
use crate::input::{InputIter, InputLength, Slice, ToUsize};
use crate::input::{InputIter, Slice, SliceLen, ToUsize};
use crate::lib::std::ops::{AddAssign, Div, RangeFrom, Shl, Shr};
use crate::{Err, IResult, Needed};

Expand All @@ -19,7 +19,7 @@ pub fn take<I, O, C, E: ParseError<(I, usize)>>(
count: C,
) -> impl Fn((I, usize)) -> IResult<(I, usize), O, E>
where
I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + SliceLen,
C: ToUsize,
O: From<u8> + AddAssign + Shl<usize, Output = O> + Shr<usize, Output = O>,
{
Expand All @@ -32,14 +32,14 @@ pub(crate) fn take_internal<I, O, E: ParseError<(I, usize)>>(
count: usize,
) -> IResult<(I, usize), O, E>
where
I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + SliceLen,
O: From<u8> + AddAssign + Shl<usize, Output = O> + Shr<usize, Output = O>,
{
if count == 0 {
Ok(((input, bit_offset), 0u8.into()))
} else {
let cnt = (count + bit_offset).div(8);
if input.input_len() * 8 < count + bit_offset {
if input.slice_len() * 8 < count + bit_offset {
Err(Err::Incomplete(Needed::new(count)))
} else {
let mut acc: O = 0_u8.into();
Expand Down Expand Up @@ -84,7 +84,7 @@ pub fn tag<I, O, C, E: ParseError<(I, usize)>>(
count: C,
) -> impl Fn((I, usize)) -> IResult<(I, usize), O, E>
where
I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength + Clone,
I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + SliceLen + Clone,
C: ToUsize,
O: From<u8> + AddAssign + Shl<usize, Output = O> + Shr<usize, Output = O> + PartialEq,
{
Expand All @@ -98,7 +98,7 @@ pub(crate) fn tag_internal<I, O, E: ParseError<(I, usize)>>(
count: usize,
) -> IResult<(I, usize), O, E>
where
I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength + Clone,
I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + SliceLen + Clone,
O: From<u8> + AddAssign + Shl<usize, Output = O> + Shr<usize, Output = O> + PartialEq,
{
let inp = input.clone();
Expand Down Expand Up @@ -131,7 +131,7 @@ where
#[deprecated(since = "8.0.0", note = "Replaced with `winnow::bits::bool`")]
pub fn bool<I, E: ParseError<(I, usize)>>(input: (I, usize)) -> IResult<(I, usize), bool, E>
where
I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + SliceLen,
{
let (res, bit): (_, u32) = take(1usize)(input)?;
Ok((res, bit != 0))
Expand Down
6 changes: 2 additions & 4 deletions src/branch/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,8 @@ macro_rules! alt_trait_inner(
alt_trait!(A B C D E F G H I J K L M N O P Q R S T U);

// Manually implement Alt for (A,), the 1-tuple type
impl<Input, Output, Error: ParseError<Input>, A: Parser<Input, Output, Error>>
Alt<Input, Output, Error> for (A,)
{
fn choice(&mut self, input: Input) -> IResult<Input, Output, Error> {
impl<I, O, E: ParseError<I>, A: Parser<I, O, E>> Alt<I, O, E> for (A,) {
fn choice(&mut self, input: I) -> IResult<I, O, E> {
self.0.parse_next(input)
}
}
Expand Down
Loading

0 comments on commit 74948e5

Please sign in to comment.