Trait winnow::stream::Stream

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

    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§

The smallest unit being parsed

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

Sequence of Tokens

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

Iterate with the offset from the current location

Required Methods§

Iterate with the offset from the current location

Returns the offaet to the end of the input

Split off the next token from the input

Finds the offset of the next matching token

Get the offset for the number of tokens into the stream

This means “0 tokens” will return 0 offset

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§

Implementors§