Skip to main content

WordRead

Trait WordRead 

Source
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§

Source

type Error: Error + Send + Sync + 'static

Source

type Word: Word

The word type (the type of the result of WordRead::read_word).

Required Methods§

Source

fn read_word(&mut self) -> Result<Self::Word, Self::Error>

Reads a word and advances the current position.

Provided Methods§

Source

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.
Source§

impl<W: Word, B: AsRef<[W]>> WordRead for MemWordReader<W, B, false>

Source§

impl<W: Word, B: AsRef<[W]>> WordRead for MemWordReader<W, B, true>

Source§

impl<W: Word, B: AsRef<[W]>> WordRead for MemWordWriterSlice<W, B>

Source§

impl<W: Word, B: Read> WordRead for WordAdapter<W, B>
where W::Bytes: Default + AsMut<[u8]>,