Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit69c0d5b

Browse files
committed
Change the standard Input impl to support any slice
The main change is that the Item is a reference instead of a copy
1 parenta44b52e commit69c0d5b

File tree

10 files changed

+374
-332
lines changed

10 files changed

+374
-332
lines changed

‎src/bits/complete.rs‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ use crate::traits::{Input, ToUsize};
3030
/// // Tries to consume 12 bits but only 8 are available
3131
/// assert_eq!(parser(([0b00010010].as_ref(), 0), 12), Err(nom::Err::Error(Error{input: ([0b00010010].as_ref(), 0), code: ErrorKind::Eof })));
3232
/// ```
33-
pubfntake<I,O,C,E:ParseError<(I,usize)>>(
33+
pubfntake<'a,I,O,C,E:ParseError<(I,usize)>>(
3434
count:C,
3535
) ->implFn((I,usize)) ->IResult<(I,usize),O,E>
3636
where
37-
I:Input<Item =u8>,
37+
I:Input<Item =&'au8>,
3838
C:ToUsize,
3939
O:From<u8> +AddAssign +Shl<usize,Output =O> +Shr<usize,Output =O>,
4040
{
@@ -59,7 +59,7 @@ where
5959
break;
6060
}
6161
let val:O =if offset ==0{
62-
byte.into()
62+
(*byte).into()
6363
}else{
6464
((byte << offset) >> offset).into()
6565
};
@@ -80,12 +80,12 @@ where
8080
}
8181

8282
/// Generates a parser taking `count` bits and comparing them to `pattern`
83-
pubfntag<I,O,C,E:ParseError<(I,usize)>>(
83+
pubfntag<'a,I,O,C,E:ParseError<(I,usize)>>(
8484
pattern:O,
8585
count:C,
8686
) ->implFn((I,usize)) ->IResult<(I,usize),O,E>
8787
where
88-
I:Input<Item =u8> +Clone,
88+
I:Input<Item =&'au8> +Clone,
8989
C:ToUsize,
9090
O:From<u8> +AddAssign +Shl<usize,Output =O> +Shr<usize,Output =O> +PartialEq,
9191
{
@@ -118,9 +118,9 @@ where
118118
/// assert_eq!(parse(([0b10000000].as_ref(), 0)), Ok((([0b10000000].as_ref(), 1), true)));
119119
/// assert_eq!(parse(([0b10000000].as_ref(), 1)), Ok((([0b10000000].as_ref(), 2), false)));
120120
/// ```
121-
pubfnbool<I,E:ParseError<(I,usize)>>(input:(I,usize)) ->IResult<(I,usize),bool,E>
121+
pubfnbool<'a,I,E:ParseError<(I,usize)>>(input:(I,usize)) ->IResult<(I,usize),bool,E>
122122
where
123-
I:Input<Item =u8>,
123+
I:Input<Item =&'au8>,
124124
{
125125
let(res, bit):(_,u32) =take(1usize)(input)?;
126126
Ok((res, bit !=0))

‎src/bits/streaming.rs‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ use crate::lib::std::ops::{AddAssign, Div, Shl, Shr};
77
usecrate::traits::{Input,ToUsize};
88

99
/// Generates a parser taking `count` bits
10-
pubfntake<I,O,C,E:ParseError<(I,usize)>>(
10+
pubfntake<'a,I,O,C,E:ParseError<(I,usize)>>(
1111
count:C,
1212
) ->implFn((I,usize)) ->IResult<(I,usize),O,E>
1313
where
14-
I:Input<Item =u8>,
14+
I:Input<Item =&'au8>,
1515
C:ToUsize,
1616
O:From<u8> +AddAssign +Shl<usize,Output =O> +Shr<usize,Output =O>,
1717
{
@@ -34,7 +34,7 @@ where
3434
break;
3535
}
3636
let val:O =if offset ==0{
37-
byte.into()
37+
(*byte).into()
3838
}else{
3939
((byte << offset) >> offset).into()
4040
};
@@ -56,12 +56,12 @@ where
5656
}
5757

5858
/// Generates a parser taking `count` bits and comparing them to `pattern`
59-
pubfntag<I,O,C,E:ParseError<(I,usize)>>(
59+
pubfntag<'a,I,O,C,E:ParseError<(I,usize)>>(
6060
pattern:O,
6161
count:C,
6262
) ->implFn((I,usize)) ->IResult<(I,usize),O,E>
6363
where
64-
I:Input<Item =u8> +Clone,
64+
I:Input<Item =&'au8> +Clone,
6565
C:ToUsize,
6666
O:From<u8> +AddAssign +Shl<usize,Output =O> +Shr<usize,Output =O> +PartialEq,
6767
{
@@ -94,9 +94,9 @@ where
9494
/// assert_eq!(parse(([0b10000000].as_ref(), 0)), Ok((([0b10000000].as_ref(), 1), true)));
9595
/// assert_eq!(parse(([0b10000000].as_ref(), 1)), Ok((([0b10000000].as_ref(), 2), false)));
9696
/// ```
97-
pubfnbool<I,E:ParseError<(I,usize)>>(input:(I,usize)) ->IResult<(I,usize),bool,E>
97+
pubfnbool<'a,I,E:ParseError<(I,usize)>>(input:(I,usize)) ->IResult<(I,usize),bool,E>
9898
where
99-
I:Input<Item =u8>,
99+
I:Input<Item =&'au8>,
100100
{
101101
let(res, bit):(_,u32) =take(1usize)(input)?;
102102
Ok((res, bit !=0))

‎src/bytes/complete.rs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ use core::marker::PhantomData;
55
usecrate::error::ParseError;
66
usecrate::internal::{IResult,Parser};
77
usecrate::traits::{Compare,FindSubstring,FindToken,ToUsize};
8-
usecrate::Complete;
98
usecrate::Emit;
109
usecrate::Input;
1110
usecrate::OutputM;
11+
usecrate::{Complete,IntoInput};
1212

1313
/// Recognizes a pattern
1414
///
@@ -358,8 +358,8 @@ where
358358
/// ```
359359
pubfntake_until<T,I,Error:ParseError<I>>(tag:T) ->implFnMut(I) ->IResult<I,I,Error>
360360
where
361-
I:Input +FindSubstring<T>,
362-
T:Input +Clone,
361+
I:Input +FindSubstring<T::Input>,
362+
T:IntoInput,
363363
{
364364
letmut parser =super::take_until(tag);
365365

‎src/bytes/mod.rs‎

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ use crate::error::ParseError;
1212
usecrate::internal::{Err,Needed,Parser};
1313
usecrate::lib::std::result::Result::*;
1414
usecrate::traits::{Compare,CompareResult};
15-
usecrate::AsChar;
1615
usecrate::Check;
1716
usecrate::ExtendInto;
1817
usecrate::FindSubstring;
@@ -23,6 +22,7 @@ use crate::Mode;
2322
usecrate::OutputM;
2423
usecrate::OutputMode;
2524
usecrate::ToUsize;
25+
usecrate::{AsChar,IntoInput};
2626

2727
/// Recognizes a pattern.
2828
///
@@ -44,11 +44,11 @@ use crate::ToUsize;
4444
/// ```
4545
pubfntag<T,I,Error:ParseError<I>>(tag:T) ->implParser<I,Output =I,Error =Error>
4646
where
47-
I:Input +Compare<T>,
48-
T:Input +Clone,
47+
I:Input +Compare<T::Input>,
48+
T:IntoInput,
4949
{
5050
Tag{
51-
tag,
51+
tag: tag.into_input(),
5252
e:PhantomData,
5353
}
5454
}
@@ -113,11 +113,11 @@ where
113113
/// ```
114114
pubfntag_no_case<T,I,Error:ParseError<I>>(tag:T) ->implParser<I,Output =I,Error =Error>
115115
where
116-
I:Input +Compare<T>,
117-
T:Input +Clone,
116+
I:Input +Compare<T::Input>,
117+
T:IntoInput,
118118
{
119119
TagNoCase{
120-
tag,
120+
tag: tag.into_input(),
121121
e:PhantomData,
122122
}
123123
}
@@ -595,11 +595,12 @@ where
595595
/// ```
596596
pubfntake_until<T,I,Error:ParseError<I>>(tag:T) ->implParser<I,Output =I,Error =Error>
597597
where
598-
I:Input +FindSubstring<T>,
599-
T:Clone,
598+
I:Input +FindSubstring<T::Input>,
599+
T:IntoInput,
600+
T::Input:Clone,
600601
{
601602
TakeUntil{
602-
tag,
603+
tag: tag.into_input(),
603604
e:PhantomData,
604605
}
605606
}

‎src/bytes/streaming.rs‎

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ use core::marker::PhantomData;
55
usecrate::error::ParseError;
66
usecrate::internal::{IResult,Parser};
77
usecrate::traits::{Compare,FindSubstring,FindToken,ToUsize};
8-
usecrate::Emit;
98
usecrate::Input;
109
usecrate::OutputM;
1110
usecrate::Streaming;
11+
usecrate::{Emit,IntoInput};
1212

1313
/// Recognizes a pattern.
1414
///
@@ -30,12 +30,12 @@ use crate::Streaming;
3030
/// ```
3131
pubfntag<T,I,Error:ParseError<I>>(tag:T) ->implFn(I) ->IResult<I,I,Error>
3232
where
33-
I:Input +Compare<T>,
34-
T:Input +Clone,
33+
I:Input +Compare<T::Input>,
34+
T:IntoInput +Clone,
3535
{
3636
move |i:I|{
3737
letmut parser =super::Tag{
38-
tag: tag.clone(),
38+
tag: tag.clone().into_input(),
3939
e:PhantomData,
4040
};
4141

@@ -64,12 +64,12 @@ where
6464
/// ```
6565
pubfntag_no_case<T,I,Error:ParseError<I>>(tag:T) ->implFn(I) ->IResult<I,I,Error>
6666
where
67-
I:Input +Compare<T>,
68-
T:Input +Clone,
67+
I:Input +Compare<T::Input>,
68+
T:IntoInput +Clone,
6969
{
7070
move |i:I|{
7171
letmut parser =super::TagNoCase{
72-
tag: tag.clone(),
72+
tag: tag.clone().into_input(),
7373
e:PhantomData,
7474
};
7575

@@ -369,8 +369,9 @@ where
369369
/// ```
370370
pubfntake_until<T,I,Error:ParseError<I>>(tag:T) ->implFnMut(I) ->IResult<I,I,Error>
371371
where
372-
I:Input +FindSubstring<T>,
373-
T:Clone,
372+
I:Input +FindSubstring<T::Input>,
373+
T:IntoInput,
374+
T::Input:Clone,
374375
{
375376
letmut parser =super::take_until(tag);
376377

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp