pub trait WordRead {
type Error: Error + Send + Sync + 'static;
type Word: Word;
// Required method
fn read_word(&mut self) -> Result<Self::Word, Self::Error>;
// Provided method
fn read_word_opt(&mut self) -> Option<Self::Word> { ... }
}Expand description
Sequential, streaming word-by-word reads.
Required Associated Types§
type Error: Error + Send + Sync + 'static
Sourcetype Word: Word
type Word: Word
The word type (the type of the result of WordRead::read_word).
Required Methods§
Provided Methods§
Sourcefn read_word_opt(&mut self) -> Option<Self::Word>
fn read_word_opt(&mut self) -> Option<Self::Word>
Reads and consumes the next word if the backend can determine cheaply
that one is available, returning None otherwise (in particular, at
the end of the stream, or when availability cannot be determined
without blocking or performing I/O).
None leaves the current position unchanged, and this method never
fails: read-and-consume is a single atomic operation, so callers can
combine it with buffered state without an error path in between (a
separate peek-then-skip pair would allow the skip to fail after the
caller committed to consuming the word).
The default implementation returns None. Backends with cheap random
access (e.g., MemWordReader) should override this method: readers
such as BufBitReader use it to provide branch-free read paths,
falling back to read_word when None is returned.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementors§
Source§impl<W: Word, B: AsRef<Vec<W>>> WordRead for MemWordWriterVec<W, B>
Available on crate feature alloc only.
impl<W: Word, B: AsRef<Vec<W>>> WordRead for MemWordWriterVec<W, B>
alloc only.