Struct combine::stream::buffered::Stream

source ·
pub struct Stream<Input>
where Input: 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 ResetStream (such as ReadStream) may use this as a way to implement ResetStream 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 buffered::Stream 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 buffered::Stream instance wraps the easy::Stream instance instead of the other way around.

// DO
buffered::Stream::new(easy::Stream(..), ..)
// DON'T
easy::Stream(buffered::Stream::new(.., ..))
parser.easy_parse(buffered::Stream::new(..));

Implementations§

source§

impl<Input> Stream<Input>
where Input: StreamOnce + Positioned, Input::Position: Clone, Input::Token: Clone,

source

pub fn new(iter: Input, lookahead: usize) -> Stream<Input>

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<Input> Debug for Stream<Input>
where Input: StreamOnce + Positioned + Debug, Input::Token: Debug, Input::Position: Debug,

source§

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

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

impl<Input> PartialEq for Stream<Input>
where Input: StreamOnce + Positioned + PartialEq, Input::Token: PartialEq, Input::Position: PartialEq,

source§

fn eq(&self, other: &Stream<Input>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<Input> Positioned for Stream<Input>
where Input: StreamOnce + Positioned,

source§

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

Returns the current position of the stream.
source§

impl<Input> ResetStream for Stream<Input>
where Input: Positioned,

§

type Checkpoint = usize

source§

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

Creates a Checkpoint at the current position which can be used to reset the stream later to the current position
source§

fn reset(&mut self, checkpoint: Self::Checkpoint) -> Result<(), Self::Error>

Attempts to reset the stream to an earlier position.
source§

impl<Input> StreamOnce for Stream<Input>
where Input: StreamOnce + Positioned, Input::Token: Clone,

§

type Token = <Input as StreamOnce>::Token

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

type Range = <Input 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::Token for this type.
§

type Position = <Input 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.
§

type Error = <Input as StreamOnce>::Error

source§

fn uncons(&mut self) -> Result<Input::Token, StreamErrorFor<Self>>

Takes a stream and removes its first token, yielding the token 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<Input> StructuralPartialEq for Stream<Input>
where Input: StreamOnce + Positioned,

Auto Trait Implementations§

§

impl<Input> Freeze for Stream<Input>
where Input: Freeze,

§

impl<Input> RefUnwindSafe for Stream<Input>
where Input: RefUnwindSafe, <Input as StreamOnce>::Token: RefUnwindSafe, <Input as StreamOnce>::Position: RefUnwindSafe,

§

impl<Input> Send for Stream<Input>
where Input: Send, <Input as StreamOnce>::Token: Send, <Input as StreamOnce>::Position: Send,

§

impl<Input> Sync for Stream<Input>
where Input: Sync, <Input as StreamOnce>::Token: Sync, <Input as StreamOnce>::Position: Sync,

§

impl<Input> Unpin for Stream<Input>
where Input: Unpin, <Input as StreamOnce>::Token: Unpin, <Input as StreamOnce>::Position: Unpin,

§

impl<Input> UnwindSafe for Stream<Input>
where Input: UnwindSafe, <Input as StreamOnce>::Token: UnwindSafe, <Input as StreamOnce>::Position: UnwindSafe,

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, U> TryFrom<U> for T
where U: Into<T>,

§

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>,

§

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<Input> Stream for Input