Trait Stream

trait Stream: Offset<<Self as Stream>::Checkpoint> + crate::lib::std::fmt::Debug

Core definition for parser input state

Associated Types

type Token: TraitBound { trait_: Path { path: "crate::lib::std::fmt::Debug", id: Id(74), args: None }, generic_params: [], modifier: None }

The smallest unit being parsed

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

type Slice: TraitBound { trait_: Path { path: "crate::lib::std::fmt::Debug", id: Id(74), args: None }, generic_params: [], modifier: None }

Sequence of Tokens

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

type IterOffsets: TraitBound { trait_: Path { path: "Iterator", id: Id(453), args: Some(AngleBracketed { args: [], constraints: [AssocItemConstraint { name: "Item", args: None, binding: Equality(Type(Tuple([Primitive("usize"), QualifiedPath { name: "Token", args: None, self_type: Generic("Self"), trait_: Some(Path { path: "", id: Id(87), args: None }) }]))) }] }) }, generic_params: [], modifier: None }

Iterate with the offset from the current location

type Checkpoint: TraitBound { trait_: Path { path: "Offset", id: Id(632), args: None }, generic_params: [], modifier: None } + TraitBound { trait_: Path { path: "Clone", id: Id(49), args: None }, generic_params: [], modifier: None } + TraitBound { trait_: Path { path: "crate::lib::std::fmt::Debug", id: Id(74), args: None }, generic_params: [], modifier: None }

A parse location within the stream

Required Methods

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

Iterate with the offset from the current location

fn eof_offset(self: &Self) -> usize

Returns the offset to the end of the input

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

Split off the next token from the input

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

Split off the next token from the input

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

Finds the offset of the next matching token

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

Split off a slice of tokens from the input

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

Save the current parse location within the stream

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

Revert the stream to a prior Self::Checkpoint

Panic

May panic if an invalid Self::Checkpoint is provided

fn raw(self: &Self) -> &dyn Debug

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

Provided Methods

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

Advance to the end of the stream

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

Advance to the end of the stream

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

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

Implementors