Trait winnow::stream::Stream

source ·
pub trait Stream: Offset + Clone + Debug {
    type Token: Debug;
    type Slice: Debug;
    type IterOffsets: Iterator<Item = (usize, Self::Token)>;

    // Required methods
    fn iter_offsets(&self) -> Self::IterOffsets;
    fn eof_offset(&self) -> usize;
    fn next_token(&self) -> Option<(Self, Self::Token)>;
    fn offset_for<P>(&self, predicate: P) -> Option<usize>
       where P: Fn(Self::Token) -> bool;
    fn offset_at(&self, tokens: usize) -> Result<usize, Needed>;
    fn next_slice(&self, offset: usize) -> (Self, Self::Slice);
}
Expand description

Core definition for parser input state

Required Associated Types§

source

type Token: Debug

The smallest unit being parsed

Example: u8 for &[u8] or char for &str

source

type Slice: Debug

Sequence of Tokens

Example: &[u8] for Located<&[u8]> or &str for Located<&str>

source

type IterOffsets: Iterator<Item = (usize, Self::Token)>

Iterate with the offset from the current location

Required Methods§

source

fn iter_offsets(&self) -> Self::IterOffsets

Iterate with the offset from the current location

source

fn eof_offset(&self) -> usize

Returns the offaet to the end of the input

source

fn next_token(&self) -> Option<(Self, Self::Token)>

Split off the next token from the input

source

fn offset_for<P>(&self, predicate: P) -> Option<usize>where P: Fn(Self::Token) -> bool,

Finds the offset of the next matching token

source

fn offset_at(&self, tokens: usize) -> Result<usize, Needed>

Get the offset for the number of tokens into the stream

This means “0 tokens” will return 0 offset

source

fn next_slice(&self, offset: usize) -> (Self, Self::Slice)

Split off a slice of tokens from the input

NOTE: For inputs with variable width tokens, like &str’s char, offset might not correspond with the number of tokens. To get a valid offset, use:

Panic

This will panic if

  • Indexes must be within bounds of the original input;
  • Indexes must uphold invariants of the stream, like for str they must lie on UTF-8 sequence boundaries.

Implementations on Foreign Types§

source§

impl<'i> Stream for &'i str

§

type Token = char

§

type Slice = &'i str

§

type IterOffsets = CharIndices<'i>

source§

fn iter_offsets(&self) -> Self::IterOffsets

source§

fn eof_offset(&self) -> usize

source§

fn next_token(&self) -> Option<(Self, Self::Token)>

source§

fn offset_for<P>(&self, predicate: P) -> Option<usize>where P: Fn(Self::Token) -> bool,

source§

fn offset_at(&self, tokens: usize) -> Result<usize, Needed>

source§

fn next_slice(&self, offset: usize) -> (Self, Self::Slice)

source§

impl<I> Stream for (I, usize)where I: Stream<Token = u8>,

§

type Token = bool

§

type Slice = (<I as Stream>::Slice, usize, usize)

§

type IterOffsets = BitOffsets<I>

source§

fn iter_offsets(&self) -> Self::IterOffsets

source§

fn eof_offset(&self) -> usize

source§

fn next_token(&self) -> Option<(Self, Self::Token)>

source§

fn offset_for<P>(&self, predicate: P) -> Option<usize>where P: Fn(Self::Token) -> bool,

source§

fn offset_at(&self, tokens: usize) -> Result<usize, Needed>

source§

fn next_slice(&self, offset: usize) -> (Self, Self::Slice)

source§

impl<'i, T> Stream for &'i [T]where T: Clone + Debug,

§

type Token = T

§

type Slice = &'i [T]

§

type IterOffsets = Enumerate<Cloned<Iter<'i, T>>>

source§

fn iter_offsets(&self) -> Self::IterOffsets

source§

fn eof_offset(&self) -> usize

source§

fn next_token(&self) -> Option<(Self, Self::Token)>

source§

fn offset_for<P>(&self, predicate: P) -> Option<usize>where P: Fn(Self::Token) -> bool,

source§

fn offset_at(&self, tokens: usize) -> Result<usize, Needed>

source§

fn next_slice(&self, offset: usize) -> (Self, Self::Slice)

Implementors§

source§

impl<'i> Stream for &'i BStr

§

type Token = u8

§

type Slice = &'i [u8]

§

type IterOffsets = Enumerate<Cloned<Iter<'i, u8>>>

source§

impl<'i> Stream for &'i Bytes

§

type Token = u8

§

type Slice = &'i [u8]

§

type IterOffsets = Enumerate<Cloned<Iter<'i, u8>>>

source§

impl<I: Stream> Stream for Located<I>

§

type Token = <I as Stream>::Token

§

type Slice = <I as Stream>::Slice

§

type IterOffsets = <I as Stream>::IterOffsets

source§

impl<I: Stream> Stream for Partial<I>

§

type Token = <I as Stream>::Token

§

type Slice = <I as Stream>::Slice

§

type IterOffsets = <I as Stream>::IterOffsets

source§

impl<I: Stream, S: Clone + Debug> Stream for Stateful<I, S>

§

type Token = <I as Stream>::Token

§

type Slice = <I as Stream>::Slice

§

type IterOffsets = <I as Stream>::IterOffsets