@@ -24,17 +24,37 @@ mod tests;
24
24
/// Return the remaining input.
25
25
///
26
26
/// ```rust
27
- /// # use nom::error::ErrorKind;
27
+ /// use nom::error;
28
+ /// use nom::Parser;
28
29
/// use nom::combinator::rest;
29
- /// assert_eq!(rest::<_,(_, ErrorKind)> ("abc"), Ok(("", "abc")));
30
- /// assert_eq!(rest::<_,(_, ErrorKind)> (""), Ok(("", "")));
30
+ /// assert_eq!(rest::<&str, error::Error<&str>>().parse_complete ("abc"), Ok(("", "abc")));
31
+ /// assert_eq!(rest::<&str, error::Error<&str>>().parse_complete (""), Ok(("", "")));
31
32
/// ```
32
33
#[ inline]
33
- pub fn rest < T , E : ParseError < T > > ( input : T ) -> IResult < T , T , E >
34
+ pub fn rest < T , E : ParseError < T > > ( ) -> impl Parser < T , Output = T , Error = E >
34
35
where
35
36
T : Input ,
36
37
{
37
- Ok ( input. take_split ( input. input_len ( ) ) )
38
+ Rest {
39
+ i : PhantomData ,
40
+ e : PhantomData ,
41
+ }
42
+ }
43
+
44
+ /// Parser implementation for [rest]
45
+ pub struct Rest < I , E > {
46
+ i : PhantomData < I > ,
47
+ e : PhantomData < E > ,
48
+ }
49
+
50
+ impl < I : Input , E : ParseError < I > > Parser < I > for Rest < I , E > {
51
+ type Output = I ;
52
+ type Error = E ;
53
+
54
+ fn process < OM : OutputMode > ( & mut self , input : I ) -> PResult < OM , I , Self :: Output , Self :: Error > {
55
+ let ( i, o) = input. take_split ( input. input_len ( ) ) ;
56
+ Ok ( ( i, OM :: Output :: bind ( || o) ) )
57
+ }
38
58
}
39
59
40
60
/// Return the length of the remaining input.
@@ -766,7 +786,7 @@ where
766
786
/// fn parser(input: &str) -> IResult<&str, &str> {
767
787
/// alt((
768
788
/// preceded(one_of("+-"), digit1),
769
- /// rest
789
+ /// rest()
770
790
/// )).parse(input)
771
791
/// }
772
792
///
@@ -789,7 +809,7 @@ where
789
809
/// fn parser(input: &str) -> IResult<&str, &str> {
790
810
/// alt((
791
811
/// preceded(one_of("+-"), cut(digit1)),
792
- /// rest
812
+ /// rest()
793
813
/// )).parse(input)
794
814
/// }
795
815
///
0 commit comments