pub struct BufferedStream<I>where
I: StreamOnce + Positioned,{ /* private fields */ }
Expand description
Stream
which buffers items from an instance of StreamOnce
into a ring buffer.
Instances of StreamOnce
which is not able to implement Resetable
(such as ReadStream
) may
use this as a way to implement Resetable
and become a full Stream
instance.
The drawback is that the buffer only stores a limited number of items which limits how many
tokens that can be reset and replayed. If a BufferedStream
is reset past this limit an error
will be returned when uncons
is next called.
NOTE: If this stream is used in conjunction with an error enhancing stream such as
easy::Stream
(also via the easy_parser
method) it is recommended that the BufferedStream
instance wraps the easy::Stream
instance instead of the other way around.
// DO
BufferedStream::new(easy::Stream(..), ..)
// DON'T
easy::Stream(BufferedStream::new(.., ..))
parser.easy_parse(BufferedStream::new(..));
Implementations§
Source§impl<I> BufferedStream<I>
impl<I> BufferedStream<I>
Sourcepub fn new(iter: I, lookahead: usize) -> BufferedStream<I>
pub fn new(iter: I, lookahead: usize) -> BufferedStream<I>
Constructs a new BufferedStream
from a StreamOnce
instance with a lookahead
number of elements that can be stored in the buffer.
Trait Implementations§
Source§impl<I> Debug for BufferedStream<I>
impl<I> Debug for BufferedStream<I>
Source§impl<I> PartialEq for BufferedStream<I>
impl<I> PartialEq for BufferedStream<I>
Source§impl<I> Positioned for BufferedStream<I>where
I: StreamOnce + Positioned,
impl<I> Positioned for BufferedStream<I>where
I: StreamOnce + Positioned,
Source§impl<I> Resetable for BufferedStream<I>where
I: Positioned,
impl<I> Resetable for BufferedStream<I>where
I: Positioned,
type Checkpoint = usize
fn checkpoint(&self) -> Self::Checkpoint
fn reset(&mut self, checkpoint: Self::Checkpoint)
Source§impl<I> StreamOnce for BufferedStream<I>
impl<I> StreamOnce for BufferedStream<I>
Source§type Item = <I as StreamOnce>::Item
type Item = <I as StreamOnce>::Item
Source§type Range = <I as StreamOnce>::Range
type Range = <I as StreamOnce>::Range
Self::Item
for this type.Source§type Position = <I as StreamOnce>::Position
type Position = <I as StreamOnce>::Position
Ord
is required to allow parsers to determine which of two positions are further ahead.type Error = <I as StreamOnce>::Error
Source§fn uncons(&mut self) -> Result<I::Item, StreamErrorFor<Self>>
fn uncons(&mut self) -> Result<I::Item, StreamErrorFor<Self>>
Err
if no element could be retrieved.Source§fn is_partial(&self) -> bool
fn is_partial(&self) -> bool
true
if this stream only contains partial input. Read moreimpl<I> StructuralPartialEq for BufferedStream<I>where
I: StreamOnce + Positioned,
Auto Trait Implementations§
impl<I> Freeze for BufferedStream<I>where
I: Freeze,
impl<I> RefUnwindSafe for BufferedStream<I>where
I: RefUnwindSafe,
<I as StreamOnce>::Item: RefUnwindSafe,
<I as StreamOnce>::Position: RefUnwindSafe,
impl<I> Send for BufferedStream<I>
impl<I> Sync for BufferedStream<I>
impl<I> Unpin for BufferedStream<I>
impl<I> UnwindSafe for BufferedStream<I>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more