@@ -24,17 +24,37 @@ mod tests;
2424/// Return the remaining input.
2525///
2626/// ```rust
27- /// # use nom::error::ErrorKind;
27+ /// use nom::error;
28+ /// use nom::Parser;
2829/// 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(("", "")));
3132/// ```
3233#[ 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 >
3435where
3536 T : Input ,
3637{
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+ }
3858}
3959
4060/// Return the length of the remaining input.
@@ -766,7 +786,7 @@ where
766786/// fn parser(input: &str) -> IResult<&str, &str> {
767787/// alt((
768788/// preceded(one_of("+-"), digit1),
769- /// rest
789+ /// rest()
770790/// )).parse(input)
771791/// }
772792///
@@ -789,7 +809,7 @@ where
789809/// fn parser(input: &str) -> IResult<&str, &str> {
790810/// alt((
791811/// preceded(one_of("+-"), cut(digit1)),
792- /// rest
812+ /// rest()
793813/// )).parse(input)
794814/// }
795815///
0 commit comments