pub trait Reader<T> {
// Required methods
fn read_next(&mut self) -> Option<T>;
fn set_head(&mut self);
fn set_tail(&mut self);
fn move_cursor_to_tail(&mut self);
fn get_sequence(&self) -> impl Iterator<Item = T>;
// Provided method
fn restart_from_tail(&mut self) { ... }
}
Expand description
A unique interface for accessing a sequence of input items.
This interface is used by the lexical analyzer when accessing input text, and needs to be
implemented for reading bytes (Reader<u8>
) before the underlying input text can be parsed.
§Implementation
A Reader should maintain 3 conceptual pointers into the input sequence of items, dubbed
head
, cursor
, and tail
. All should initially point to the beginning of the sequence. The
interface provides an API for managing these pointers, and accessing the underlying data. This
API is internally used by lexical analyzers.
Required Methods§
Sourcefn read_next(&mut self) -> Option<T>
fn read_next(&mut self) -> Option<T>
Reads the item pointed by cursor
, and advance cursor
to the next item.
Returns None if cursor
points to no valid item (for example - when the input is
exhausted).
Sourcefn move_cursor_to_tail(&mut self)
fn move_cursor_to_tail(&mut self)
Set cursor
to point to the item pointed by tail
.
Sourcefn get_sequence(&self) -> impl Iterator<Item = T>
fn get_sequence(&self) -> impl Iterator<Item = T>
Get an iterator over all items between head
(inclusive) and tail
(exclusive).
Provided Methods§
Sourcefn restart_from_tail(&mut self)
fn restart_from_tail(&mut self)
Set cursor
and head
to point to the item pointed by tail
.
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.