_

Trait _ 

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

Show 16 methods // Required methods fn iter_offsets(&self) -> Self::IterOffsets; fn eof_offset(&self) -> usize; fn next_token(&mut self) -> Option<Self::Token>; fn peek_token(&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 peek_slice(&self, offset: usize) -> Self::Slice; fn checkpoint(&self) -> Self::Checkpoint; fn reset(&mut self, checkpoint: &Self::Checkpoint); fn raw(&self) -> &dyn Debug; // Provided methods unsafe fn next_slice_unchecked(&mut self, offset: usize) -> Self::Slice { ... } unsafe fn peek_slice_unchecked(&self, offset: usize) -> Self::Slice { ... } fn finish(&mut self) -> Self::Slice { ... } fn peek_finish(&self) -> Self::Slice where Self: Clone { ... } fn trace(&self, f: &mut Formatter<'_>) -> Result<(), Error> { ... }
}
Expand description

Core definition for parser input state

Required Associated Types§

type Token: Debug

The smallest unit being parsed

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

type Slice: Debug

Sequence of Tokens

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

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

Iterate with the offset from the current location

type Checkpoint: Offset + Clone + Debug

A parse location within the stream

Required Methods§

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

Iterate with the offset from the current location

fn eof_offset(&self) -> usize

Returns the offset to the end of the input

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

Split off the next token from the input

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

Split off the next token from the input

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

Finds the offset of the next matching token

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

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.

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

Split off a slice of tokens from the input

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

Save the current parse location within the stream

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

fn raw(&self) -> &dyn Debug

👎Deprecated since 0.7.10: Replaced with Stream::trace

Deprecated for callers as of 0.7.10, instead call Stream::trace

Provided Methods§

unsafe fn next_slice_unchecked(&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:

§Safety

Callers of this function are responsible that these preconditions are satisfied:

  • 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.

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

Split off a slice of tokens from the input

§Safety

Callers of this function are responsible that these preconditions are satisfied:

  • 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.

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

Advance to the end of the stream

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

Advance to the end of the stream

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

Write out a single-line summary of the current parse location

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§

§

impl<'i> Stream for &'i str

§

type Token = char

§

type Slice = &'i str

§

type IterOffsets = CharIndices<'i>

§

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

§

fn iter_offsets(&self) -> <&'i str as Stream>::IterOffsets

§

fn eof_offset(&self) -> usize

§

fn next_token(&mut self) -> Option<<&'i str as Stream>::Token>

§

fn peek_token(&self) -> Option<<&'i str as Stream>::Token>

§

fn offset_for<P>(&self, predicate: P) -> Option<usize>
where P: Fn(<&'i str as Stream>::Token) -> bool,

§

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

§

fn next_slice(&mut self, offset: usize) -> <&'i str as Stream>::Slice

§

unsafe fn next_slice_unchecked( &mut self, offset: usize, ) -> <&'i str as Stream>::Slice

§

fn peek_slice(&self, offset: usize) -> <&'i str as Stream>::Slice

§

unsafe fn peek_slice_unchecked( &self, offset: usize, ) -> <&'i str as Stream>::Slice

§

fn checkpoint(&self) -> <&'i str as Stream>::Checkpoint

§

fn reset(&mut self, checkpoint: &<&'i str as Stream>::Checkpoint)

§

fn raw(&self) -> &dyn Debug

👎Deprecated since 0.7.10: Replaced with Stream::trace
§

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

§

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

§

fn iter_offsets(&self) -> <&'i [T] as Stream>::IterOffsets

§

fn eof_offset(&self) -> usize

§

fn next_token(&mut self) -> Option<<&'i [T] as Stream>::Token>

§

fn peek_token(&self) -> Option<<&'i [T] as Stream>::Token>

§

fn offset_for<P>(&self, predicate: P) -> Option<usize>
where P: Fn(<&'i [T] as Stream>::Token) -> bool,

§

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

§

fn next_slice(&mut self, offset: usize) -> <&'i [T] as Stream>::Slice

§

unsafe fn next_slice_unchecked( &mut self, offset: usize, ) -> <&'i [T] as Stream>::Slice

§

fn peek_slice(&self, offset: usize) -> <&'i [T] as Stream>::Slice

§

unsafe fn peek_slice_unchecked( &self, offset: usize, ) -> <&'i [T] as Stream>::Slice

§

fn checkpoint(&self) -> <&'i [T] as Stream>::Checkpoint

§

fn reset(&mut self, checkpoint: &<&'i [T] as Stream>::Checkpoint)

§

fn raw(&self) -> &dyn Debug

👎Deprecated since 0.7.10: Replaced with Stream::trace
§

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

§

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

§

type Token = bool

§

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

§

type IterOffsets = BitOffsets<I>

§

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

§

fn iter_offsets(&self) -> <(I, usize) as Stream>::IterOffsets

§

fn eof_offset(&self) -> usize

§

fn next_token(&mut self) -> Option<<(I, usize) as Stream>::Token>

§

fn peek_token(&self) -> Option<<(I, usize) as Stream>::Token>

§

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

§

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

§

fn next_slice(&mut self, offset: usize) -> <(I, usize) as Stream>::Slice

§

fn peek_slice(&self, offset: usize) -> <(I, usize) as Stream>::Slice

§

fn checkpoint(&self) -> <(I, usize) as Stream>::Checkpoint

§

fn reset(&mut self, checkpoint: &<(I, usize) as Stream>::Checkpoint)

§

fn raw(&self) -> &dyn Debug

👎Deprecated since 0.7.10: Replaced with Stream::trace

Implementors§

§

impl<'i> Stream for &'i BStr

§

type Token = u8

§

type Slice = &'i [u8]

§

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

§

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

§

impl<'i> Stream for &'i Bytes

§

type Token = u8

§

type Slice = &'i [u8]

§

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

§

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

§

impl<'t, T> Stream for TokenSlice<'t, T>
where T: Debug + Clone,

§

type Token = &'t T

§

type Slice = &'t [T]

§

type IterOffsets = Enumerate<Iter<'t, T>>

§

type Checkpoint = Checkpoint<&'t [T], TokenSlice<'t, T>>

§

impl<I> Stream for LocatingSlice<I>
where I: Stream,

§

type Token = <I as Stream>::Token

§

type Slice = <I as Stream>::Slice

§

type IterOffsets = <I as Stream>::IterOffsets

§

type Checkpoint = Checkpoint<<I as Stream>::Checkpoint, LocatingSlice<I>>

§

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

§

type Token = <I as Stream>::Token

§

type Slice = <I as Stream>::Slice

§

type IterOffsets = <I as Stream>::IterOffsets

§

type Checkpoint = Checkpoint<<I as Stream>::Checkpoint, Partial<I>>

§

impl<I, S> Stream for Stateful<I, S>
where I: Stream, S: Debug,

§

type Token = <I as Stream>::Token

§

type Slice = <I as Stream>::Slice

§

type IterOffsets = <I as Stream>::IterOffsets

§

type Checkpoint = Checkpoint<<I as Stream>::Checkpoint, Stateful<I, S>>