winnow::stream

Trait Stream

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

Show 13 methods // Required methods fn iter_offsets(&self) -> Self::IterOffsets; fn eof_offset(&self) -> usize; fn next_token(&mut self) -> Option<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(&mut self, offset: usize) -> Self::Slice; fn checkpoint(&self) -> Self::Checkpoint; fn reset(&mut self, checkpoint: &Self::Checkpoint); fn raw(&self) -> &dyn Debug; // Provided methods fn peek_token(&self) -> Option<(Self, Self::Token)> where Self: Clone { ... } fn peek_slice(&self, offset: usize) -> (Self, Self::Slice) where Self: Clone { ... } fn finish(&mut self) -> Self::Slice { ... } fn peek_finish(&self) -> (Self, Self::Slice) where Self: Clone { ... }
}
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

Source

type Checkpoint: Offset + Clone + Debug

A parse location within the stream

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 offset to the end of the input

Source

fn next_token(&mut self) -> Option<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(&mut self, offset: usize) -> 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.
Source

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

Save the current parse location within the stream

Source

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

Revert the stream to a prior Self::Checkpoint

§Panic

May panic if an invalid Self::Checkpoint is provided

Source

fn raw(&self) -> &dyn Debug

Return the inner-most stream

Provided Methods§

Source

fn peek_token(&self) -> Option<(Self, Self::Token)>
where Self: Clone,

Split off the next token from the input

Source

fn peek_slice(&self, offset: usize) -> (Self, Self::Slice)
where Self: Clone,

Split off a slice of tokens from the input

Source

fn finish(&mut self) -> Self::Slice

Advance to the end of the stream

Source

fn peek_finish(&self) -> (Self, Self::Slice)
where Self: Clone,

Advance to the end of the stream

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<'i> Stream for &'i str

Source§

type Token = char

Source§

type Slice = &'i str

Source§

type IterOffsets = CharIndices<'i>

Source§

type Checkpoint = Checkpoint<&'i str, &'i str>

Source§

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

Source§

fn eof_offset(&self) -> usize

Source§

fn next_token(&mut self) -> Option<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(&mut self, offset: usize) -> Self::Slice

Source§

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

Source§

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

Source§

fn raw(&self) -> &dyn Debug

Source§

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

Source§

type Token = T

Source§

type Slice = &'i [T]

Source§

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

Source§

type Checkpoint = Checkpoint<&'i [T], &'i [T]>

Source§

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

Source§

fn eof_offset(&self) -> usize

Source§

fn next_token(&mut self) -> Option<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(&mut self, offset: usize) -> Self::Slice

Source§

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

Source§

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

Source§

fn raw(&self) -> &dyn Debug

Source§

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

Source§

type Token = bool

Source§

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

Source§

type IterOffsets = BitOffsets<I>

Source§

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

Source§

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

Source§

fn eof_offset(&self) -> usize

Source§

fn next_token(&mut self) -> Option<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(&mut self, offset: usize) -> Self::Slice

Source§

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

Source§

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

Source§

fn raw(&self) -> &dyn Debug

Implementors§