Trait constriction::backends::WriteWords[][src]

pub trait WriteWords<Word> {
    type WriteError: Debug;
    fn write(&mut self, word: Word) -> Result<(), Self::WriteError>;

    fn extend_from_iter(
        &mut self,
        iter: impl Iterator<Item = Word>
    ) -> Result<(), Self::WriteError> { ... }
fn maybe_full(&self) -> bool { ... } }
Expand description

A trait for sinks of compressed data (mainly used by encoders).

See the module-level documentation for more information.

Associated Types

The error type that can occur when writing to the data sink, or Infallible.

This type should be Infallible if writing cannot fail, so that the compiler can optimize out any error checks (see also UnwrapInfallible).

An example error could be that the data sink is “full”, if that’s a state that the data sink can be in. Note the asymmetry compared to ReadWords: while we consider an attempt to write to a “full” WriteWords as an error, we consider an attempt to read from an “empty” ReadWords as a normal operation (that returns Ok(None)). This is because it is a common task to read all data from a data source until it is empty (and attempting to read past the “empty” state is often the only way to detect emptyness) whereas it is not a common task to intentionally write to a data sink until it is full (and therefore attempting to write to a full data sink is typically an error).

Required methods

Writes a single Word to the data sink and advances the state of the data sink accordingly (i.e., so that the next write won’t overwrite the current Word).

Provided methods

Writes a sequence of Words to the data sink, short-circuiting on error.

The default implementation calls write for each word. You may want to overwrite this if your data sink can perform additional optimizations (e.g., by utilizing the provided iterator’s size_hint).

Returns true if the data sink could be full

It is always correct to return true from this method, even if the concept of being “full” doesn’t apply to the data sink. The default implementation always returns true. The precise meaning of “full” may vary between data sinks. A data sink that’s “not full” (i.e., where this method returns false) may still return an error when trying to write to it.

Implementations on Foreign Types

The only way how writing to a Vec<Word> can fail is if a memory allocation fails, which is typically treated as a fatal error (i.e., aborts) in Rust.

Appends the word to the end of the vector (= top of the stack)

The only way how writing to a Vec<Word> can fail is if a memory allocation fails, which is typically treated as a fatal error (i.e., aborts) in Rust.

Appends the word to the end of the vector (= top of the stack)

Implementors