diff --git a/src/parser/range.rs b/src/parser/range.rs index 7b53fe64..ff21d708 100644 --- a/src/parser/range.rs +++ b/src/parser/range.rs @@ -701,6 +701,48 @@ where [ .then_partial(|&mut len| take(len)) } } +#[derive(Copy, Clone)] +pub struct Offset

(usize, P); + +impl Parser for Offset

+where + Input: RangeStream, + P: Parser, +{ + type Output = O; + type PartialState = (); + + #[inline] + fn parse_lazy(&mut self, input: &mut Input) -> ParseResult::Error> { + let before = input.checkpoint(); + ctry!(uncons_range(input, self.0)); + let result = self.1.parse_lazy(input); + ctry!(input.reset(before).committed()); + let (o, _input) = ctry!(result); + PeekOk(o) + } + + forward_parser!(Input, add_error add_committed_expected_error parser_count, 1); +} + +/// Parser that skip `count` and then parse data resetting back to original location +/// +/// ``` +/// # extern crate combine; +/// # use combine::parser::range::{take, offset}; +/// # use combine::*; +/// # fn main() { +/// let mut parser = offset(3, take(3)); +/// assert_eq!(parser.parse("1234567890"), Ok(("456", "1234567890"))); +/// # } +/// ``` +pub fn offset(count: usize, p: P) -> Offset

+where + P: Parser, + Input: RangeStream, +{ + Offset(count, p) +} #[cfg(test)] mod tests { diff --git a/src/stream/buf_reader.rs b/src/stream/buf_reader.rs index fa7b928b..04dbc3ed 100644 --- a/src/stream/buf_reader.rs +++ b/src/stream/buf_reader.rs @@ -8,11 +8,7 @@ use std::io::{self, BufRead, Read}; ))] use std::pin::Pin; -#[cfg(any( - feature = "futures-03", - feature = "tokio-02", - feature = "tokio-03" -))] +#[cfg(any(feature = "futures-03", feature = "tokio-02", feature = "tokio-03"))] use std::mem::MaybeUninit; #[cfg(feature = "futures-core-03")] diff --git a/src/stream/decoder.rs b/src/stream/decoder.rs index ad034f87..1bc96c39 100644 --- a/src/stream/decoder.rs +++ b/src/stream/decoder.rs @@ -136,7 +136,7 @@ impl Decoder { impl Decoder where - C: , + C:, { #[doc(hidden)] pub fn __before_parse(&mut self, mut reader: R) -> io::Result<()>