Trait binator::Streaming

source ·
pub trait Streaming: Sized + Clone + Eq + Debug {
    type Item: Debug;
    type Error: Debug;
    type Span: Debug + Streaming;

    // Required methods
    fn split_first(self) -> Split<Self::Item, Self, Self::Error>;
    fn split_at(self, mid: usize) -> Split<Self::Span, Self, Self::Error>;
    fn split_last(self) -> Split<Self::Item, Self, Self::Error>;
    fn all(self) -> Result<Success<Self::Span, Self>, Self::Error>;
    fn diff(self, other: &Self) -> Result<Self::Span, Self>;

    // Provided method
    fn consume(self) -> Self { ... }
}
Expand description

This trait must be implement by all struct that want to be a stream for binator.

Required Associated Types§

source

type Item: Debug

Item produced by the stream

source

type Error: Debug

Error that a stream can produce

source

type Span: Debug + Streaming

Span used to represent a delimited part of the stream

Required Methods§

source

fn split_first(self) -> Split<Self::Item, Self, Self::Error>

Will remove the first item from the stream

source

fn split_at(self, mid: usize) -> Split<Self::Span, Self, Self::Error>

Will split the stream in half

source

fn split_last(self) -> Split<Self::Item, Self, Self::Error>

Will remove the last item from the stream, not this is know as backtracking. It’s generally not recommanded to do this, not all stream will be able to implement this

source

fn all(self) -> Result<Success<Self::Span, Self>, Self::Error>

Will return all possible Item from the stream, note that again use this with caution.

source

fn diff(self, other: &Self) -> Result<Self::Span, Self>

Allow to get a span between two stream, self must be a stream earlier than other

Provided Methods§

source

fn consume(self) -> Self

This should be used with maximum care. This is used to tell to the stream, “drop already read data”. It’s mean all data before the cursor of this stream is gone. It’s invalidate any Stream or Span with cursor that point to purged data. The purpose of this is to avoid keep all data in memory if not needed. This should be call only by end user parser or be documented properly.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl<'a> Streaming for &'a [u8]

§

type Error = Infallible

§

type Item = u8

§

type Span = &'a [u8]

source§

fn split_first(self) -> Split<Self::Item, Self, Self::Error>

source§

fn split_at(self, mid: usize) -> Split<Self, Self, Self::Error>

source§

fn split_last(self) -> Split<Self::Item, Self, Self::Error>

source§

fn all(self) -> Result<Success<Self::Span, Self>, Self::Error>

source§

fn diff(self, other: &Self) -> Result<Self, Self>

Implementors§

source§

impl Streaming for VecStream

source§

impl<Reader: Read + Debug, const N: usize> Streaming for ReaderStream<Reader, N>

§

type Error = Error

§

type Item = u8

§

type Span = ReaderStream<Reader, N>