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 15 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 trace(&self, f: &mut Formatter<'_>) -> Result;
// 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 { ... }
}Expand description
Core definition for parser input state
Required Associated Types§
Sourcetype Slice: Debug
type Slice: Debug
Sequence of Tokens
Example: &[u8] for LocatingSlice<&[u8]> or &str for LocatingSlice<&str>
Sourcetype IterOffsets: Iterator<Item = (usize, Self::Token)>
type IterOffsets: Iterator<Item = (usize, Self::Token)>
Iterate with the offset from the current location
Sourcetype Checkpoint: Offset + Clone + Debug
type Checkpoint: Offset + Clone + Debug
A parse location within the stream
Required Methods§
Sourcefn iter_offsets(&self) -> Self::IterOffsets
fn iter_offsets(&self) -> Self::IterOffsets
Iterate with the offset from the current location
Sourcefn eof_offset(&self) -> usize
fn eof_offset(&self) -> usize
Returns the offset to the end of the input
Sourcefn next_token(&mut self) -> Option<Self::Token>
fn next_token(&mut self) -> Option<Self::Token>
Split off the next token from the input
Sourcefn peek_token(&self) -> Option<Self::Token>
fn peek_token(&self) -> Option<Self::Token>
Split off the next token from the input
Sourcefn offset_for<P>(&self, predicate: P) -> Option<usize>
fn offset_for<P>(&self, predicate: P) -> Option<usize>
Finds the offset of the next matching token
Sourcefn offset_at(&self, tokens: usize) -> Result<usize, Needed>
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
Sourcefn next_slice(&mut self, offset: usize) -> Self::Slice
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
strthey must lie on UTF-8 sequence boundaries.
Sourcefn peek_slice(&self, offset: usize) -> Self::Slice
fn peek_slice(&self, offset: usize) -> Self::Slice
Split off a slice of tokens from the input
Sourcefn checkpoint(&self) -> Self::Checkpoint
fn checkpoint(&self) -> Self::Checkpoint
Save the current parse location within the stream
Sourcefn reset(&mut self, checkpoint: &Self::Checkpoint)
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
Provided Methods§
Sourceunsafe fn next_slice_unchecked(&mut self, offset: usize) -> Self::Slice
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
strthey must lie on UTF-8 sequence boundaries.
Sourceunsafe fn peek_slice_unchecked(&self, offset: usize) -> Self::Slice
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
strthey must lie on UTF-8 sequence boundaries.
Sourcefn peek_finish(&self) -> Self::Slicewhere
Self: Clone,
fn peek_finish(&self) -> Self::Slicewhere
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".