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:
u8for&[u8]orcharfor&strtype Slice: TraitBound { trait_: Path { path: "crate::lib::std::fmt::Debug", id: Id(74), args: None }, generic_params: [], modifier: None }Sequence of
TokensExample:
&[u8]forLocatingSlice<&[u8]>or&strforLocatingSlice<&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 >::IterOffsetsIterate with the offset from the current location
fn eof_offset(self: &Self) -> usizeReturns 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) -> boolFinds the offset of the next matching token
fn offset_at(self: &Self, tokens: usize) -> Result<usize, Needed>Get the offset for the number of
tokensinto the streamThis means "0 tokens" will return
0offsetfn next_slice(self: &mut Self, offset: usize) -> <Self as >::SliceSplit off a slice of tokens from the input
Note: For inputs with variable width tokens, like
&str'schar,offsetmight 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.
fn peek_slice(self: &Self, offset: usize) -> <Self as >::SliceSplit off a slice of tokens from the input
fn checkpoint(self: &Self) -> <Self as >::CheckpointSave the current parse location within the stream
fn reset(self: &mut Self, checkpoint: &<Self as >::Checkpoint)Revert the stream to a prior
Self::CheckpointPanic
May panic if an invalid
Self::Checkpointis providedfn raw(self: &Self) -> &dyn DebugDeprecated 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 >::SliceSplit off a slice of tokens from the input
Note: For inputs with variable width tokens, like
&str'schar,offsetmight 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.
unsafe fn peek_slice_unchecked(self: &Self, offset: usize) -> <Self as >::SliceSplit 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.
fn finish(self: &mut Self) -> <Self as >::SliceAdvance to the end of the stream
fn peek_finish(self: &Self) -> <Self as >::Slice where Self: CloneAdvance to the end of the stream
fn trace(self: &Self, f: &mut Formatter<'_>) -> ResultWrite out a single-line summary of the current parse location
Implementors
impl<I: Stream, S: crate::lib::std::fmt::Debug> Stream for Stateful<I, S>impl<'i, T> Stream for &'i [T]impl<I: Stream> Stream for LocatingSlice<I>impl<'i> Stream for &'i strimpl<I> Stream for (I, usize)impl<'i> Stream for &'i Bytesimpl<I: Stream> Stream for Partial<I>impl<'i> Stream for &'i BStrimpl<'t, T> Stream for TokenSlice<'t, T>