combine::stream::buffered

Struct BufferedStream

Source
pub struct BufferedStream<I>{ /* 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>

Source

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>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<I> PartialEq for BufferedStream<I>

Source§

fn eq(&self, other: &BufferedStream<I>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<I> Positioned for BufferedStream<I>

Source§

fn position(&self) -> Self::Position

Returns the current position of the stream.
Source§

impl<I> Resetable for BufferedStream<I>
where I: Positioned,

Source§

type Checkpoint = usize

Source§

fn checkpoint(&self) -> Self::Checkpoint

Source§

fn reset(&mut self, checkpoint: Self::Checkpoint)

Source§

impl<I> StreamOnce for BufferedStream<I>

Source§

type Item = <I as StreamOnce>::Item

The type of items which is yielded from this stream.
Source§

type Range = <I as StreamOnce>::Range

The type of a range of items yielded from this stream. Types which do not a have a way of yielding ranges of items should just use the Self::Item for this type.
Source§

type Position = <I as StreamOnce>::Position

Type which represents the position in a stream. Ord is required to allow parsers to determine which of two positions are further ahead.
Source§

type Error = <I as StreamOnce>::Error

Source§

fn uncons(&mut self) -> Result<I::Item, StreamErrorFor<Self>>

Takes a stream and removes its first item, yielding the item and the rest of the elements. Returns Err if no element could be retrieved.
Source§

fn is_partial(&self) -> bool

Returns true if this stream only contains partial input. Read more
Source§

impl<I> StructuralPartialEq for BufferedStream<I>

Auto Trait Implementations§

§

impl<I> Freeze for BufferedStream<I>
where I: Freeze,

§

impl<I> RefUnwindSafe for BufferedStream<I>

§

impl<I> Send for BufferedStream<I>
where I: Send, <I as StreamOnce>::Item: Send, <I as StreamOnce>::Position: Send,

§

impl<I> Sync for BufferedStream<I>
where I: Sync, <I as StreamOnce>::Item: Sync, <I as StreamOnce>::Position: Sync,

§

impl<I> Unpin for BufferedStream<I>
where I: Unpin, <I as StreamOnce>::Item: Unpin, <I as StreamOnce>::Position: Unpin,

§

impl<I> UnwindSafe for BufferedStream<I>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<I> Stream for I