Skip to content

Commit

Permalink
remove the InputLength trait (#1747)
Browse files Browse the repository at this point in the history
  • Loading branch information
Geal committed May 5, 2024
1 parent d8e67fe commit 46eaa0a
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 98 deletions.
10 changes: 5 additions & 5 deletions src/bytes/complete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use core::marker::PhantomData;

use crate::error::ParseError;
use crate::internal::{IResult, Parser};
use crate::traits::{Compare, FindSubstring, FindToken, InputLength, ToUsize};
use crate::traits::{Compare, FindSubstring, FindToken, ToUsize};
use crate::Complete;
use crate::Emit;
use crate::Input;
Expand Down Expand Up @@ -32,7 +32,7 @@ use crate::OutputM;
pub fn tag<T, I, Error: ParseError<I>>(tag: T) -> impl Fn(I) -> IResult<I, I, Error>
where
I: Input + Compare<T>,
T: InputLength + Clone,
T: Input + Clone,
{
move |i: I| {
let mut parser = super::Tag {
Expand Down Expand Up @@ -68,7 +68,7 @@ where
pub fn tag_no_case<T, I, Error: ParseError<I>>(tag: T) -> impl Fn(I) -> IResult<I, I, Error>
where
I: Input + Compare<T>,
T: InputLength + Clone,
T: Input + Clone,
{
move |i: I| {
let mut parser = super::TagNoCase {
Expand Down Expand Up @@ -359,7 +359,7 @@ where
pub fn take_until<T, I, Error: ParseError<I>>(tag: T) -> impl FnMut(I) -> IResult<I, I, Error>
where
I: Input + FindSubstring<T>,
T: InputLength + Clone,
T: Input + Clone,
{
let mut parser = super::take_until(tag);

Expand Down Expand Up @@ -388,7 +388,7 @@ where
pub fn take_until1<T, I, Error: ParseError<I>>(tag: T) -> impl FnMut(I) -> IResult<I, I, Error>
where
I: Input + FindSubstring<T>,
T: InputLength + Clone,
T: Input + Clone,
{
let mut parser = super::take_until1(tag);

Expand Down
10 changes: 5 additions & 5 deletions src/bytes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::error::ErrorKind;
use crate::error::ParseError;
use crate::internal::{Err, Needed, Parser};
use crate::lib::std::result::Result::*;
use crate::traits::{Compare, CompareResult, InputLength};
use crate::traits::{Compare, CompareResult};
use crate::AsChar;
use crate::Check;
use crate::ExtendInto;
Expand Down Expand Up @@ -45,7 +45,7 @@ use crate::ToUsize;
pub fn tag<T, I, Error: ParseError<I>>(tag: T) -> impl Parser<I, Output = I, Error = Error>
where
I: Input + Compare<T>,
T: InputLength + Clone,
T: Input + Clone,
{
Tag {
tag,
Expand All @@ -62,7 +62,7 @@ pub struct Tag<T, E> {
impl<I, Error: ParseError<I>, T> Parser<I> for Tag<T, Error>
where
I: Input + Compare<T>,
T: InputLength + Clone,
T: Input + Clone,
{
type Output = I;

Expand Down Expand Up @@ -114,7 +114,7 @@ where
pub fn tag_no_case<T, I, Error: ParseError<I>>(tag: T) -> impl Parser<I, Output = I, Error = Error>
where
I: Input + Compare<T>,
T: InputLength + Clone,
T: Input + Clone,
{
TagNoCase {
tag,
Expand All @@ -131,7 +131,7 @@ pub struct TagNoCase<T, E> {
impl<I, Error: ParseError<I>, T> Parser<I> for TagNoCase<T, Error>
where
I: Input + Compare<T>,
T: InputLength + Clone,
T: Input + Clone,
{
type Output = I;

Expand Down
8 changes: 4 additions & 4 deletions src/bytes/streaming.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use core::marker::PhantomData;

use crate::error::ParseError;
use crate::internal::{IResult, Parser};
use crate::traits::{Compare, FindSubstring, FindToken, InputLength, ToUsize};
use crate::traits::{Compare, FindSubstring, FindToken, ToUsize};
use crate::Emit;
use crate::Input;
use crate::OutputM;
Expand All @@ -31,7 +31,7 @@ use crate::Streaming;
pub fn tag<T, I, Error: ParseError<I>>(tag: T) -> impl Fn(I) -> IResult<I, I, Error>
where
I: Input + Compare<T>,
T: InputLength + Clone,
T: Input + Clone,
{
move |i: I| {
let mut parser = super::Tag {
Expand Down Expand Up @@ -65,7 +65,7 @@ where
pub fn tag_no_case<T, I, Error: ParseError<I>>(tag: T) -> impl Fn(I) -> IResult<I, I, Error>
where
I: Input + Compare<T>,
T: InputLength + Clone,
T: Input + Clone,
{
move |i: I| {
let mut parser = super::TagNoCase {
Expand Down Expand Up @@ -338,7 +338,7 @@ where
/// ```
pub fn take<C, I, Error: ParseError<I>>(count: C) -> impl FnMut(I) -> IResult<I, I, Error>
where
I: Input + InputLength,
I: Input,
C: ToUsize,
{
let mut parser = super::take(count);
Expand Down
4 changes: 2 additions & 2 deletions src/bytes/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -636,10 +636,10 @@ fn tag_fixed_size_array() {
use crate::bytes::streaming::tag;

fn test(i: &[u8]) -> IResult<&[u8], &[u8]> {
tag([0x42])(i)
tag(&[0x42][..])(i)
}
fn test2(i: &[u8]) -> IResult<&[u8], &[u8]> {
tag(&[0x42])(i)
tag(&[0x42][..])(i)
}
let input = [0x42, 0x00];
assert_eq!(test(&input), Ok((&b"\x00"[..], &b"\x42"[..])));
Expand Down
4 changes: 2 additions & 2 deletions src/character/complete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::combinator::opt;
use crate::error::ErrorKind;
use crate::error::ParseError;
use crate::internal::{Err, IResult};
use crate::traits::{AsChar, FindToken, Input, InputLength};
use crate::traits::{AsChar, FindToken, Input};
use crate::traits::{Compare, CompareResult};
use crate::Complete;
use crate::Emit;
Expand Down Expand Up @@ -208,7 +208,7 @@ where
/// ```
pub fn line_ending<T, E: ParseError<T>>(input: T) -> IResult<T, T, E>
where
T: Input + InputLength,
T: Input,
T: Compare<&'static str>,
{
match input.compare("\n") {
Expand Down
10 changes: 5 additions & 5 deletions src/combinator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::lib::std::convert::Into;
use crate::lib::std::fmt::Debug;
use crate::lib::std::mem::transmute;
use crate::lib::std::ops::{Range, RangeFrom, RangeTo};
use crate::traits::{AsChar, Input, InputLength, ParseTo};
use crate::traits::{AsChar, Input, ParseTo};
use crate::traits::{Compare, CompareResult, Offset};

#[cfg(test)]
Expand Down Expand Up @@ -48,7 +48,7 @@ where
#[inline]
pub fn rest_len<T, E: ParseError<T>>(input: T) -> IResult<T, usize, E>
where
T: InputLength,
T: Input,
{
let len = input.input_len();
Ok((input, len))
Expand Down Expand Up @@ -363,7 +363,7 @@ where
/// assert_eq!(parser(""), Ok(("", "")));
/// # }
/// ```
pub fn eof<I: InputLength + Clone, E: ParseError<I>>(input: I) -> IResult<I, I, E> {
pub fn eof<I: Input + Clone, E: ParseError<I>>(input: I) -> IResult<I, I, E> {
if input.input_len() == 0 {
let clone = input.clone();
Ok((input, clone))
Expand Down Expand Up @@ -443,7 +443,7 @@ pub fn all_consuming<I, E: ParseError<I>, F>(
parser: F,
) -> impl Parser<I, Output = <F as Parser<I>>::Output, Error = E>
where
I: InputLength,
I: Input,
F: Parser<I, Error = E>,
{
AllConsuming { parser }
Expand All @@ -456,7 +456,7 @@ pub struct AllConsuming<F> {

impl<I, F> Parser<I> for AllConsuming<F>
where
I: InputLength,
I: Input,
F: Parser<I>,
{
type Output = <F as Parser<I>>::Output;
Expand Down

0 comments on commit 46eaa0a

Please sign in to comment.