use crate::{ error::ParseResult, stream::{Positioned, RangeStreamOnce, ResetStream, StreamErrorFor, StreamOnce}, }; #[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Debug)] pub struct Stream { pub stream: S, pub state: U, } impl Positioned for Stream where S: Positioned, { #[inline] fn position(&self) -> Self::Position { self.stream.position() } } impl ResetStream for Stream where S: ResetStream, { type Checkpoint = S::Checkpoint; #[inline] fn checkpoint(&self) -> Self::Checkpoint { self.stream.checkpoint() } #[inline] fn reset(&mut self, checkpoint: Self::Checkpoint) -> Result<(), Self::Error> { self.stream.reset(checkpoint) } } impl StreamOnce for Stream where S: StreamOnce, { type Token = S::Token; type Range = S::Range; type Position = S::Position; type Error = S::Error; #[inline] fn uncons(&mut self) -> Result> { self.stream.uncons() } fn is_partial(&self) -> bool { self.stream.is_partial() } } impl RangeStreamOnce for Stream where S: RangeStreamOnce, { #[inline] fn uncons_range(&mut self, size: usize) -> Result> { self.stream.uncons_range(size) } #[inline] fn uncons_while(&mut self, f: F) -> Result> where F: FnMut(Self::Token) -> bool, { self.stream.uncons_while(f) } fn uncons_while1(&mut self, f: F) -> ParseResult> where F: FnMut(Self::Token) -> bool, { self.stream.uncons_while1(f) } #[inline] fn distance(&self, end: &Self::Checkpoint) -> usize { self.stream.distance(end) } #[inline] fn range(&self) -> Self::Range { self.stream.range() } }