Skip to main content

Codex

Trait Codex 

Source
pub trait Codex: Send + Sync {
    // Required methods
    fn encode(&self, byte: u8) -> u8;
    fn decode(&self, byte: u8) -> u8;
}
Expand description

Byte-wise transformation applied to all stored bytes.

§Implementor contract

  • Involution. For every byte b, self.decode(self.encode(b)) == b. Equivalently, the transformation is its own inverse.
  • Constant-time. Implementations should be branch-free; the canonical shape is a 256-entry lookup table.
  • Send + Sync. Codex instances are shared across threads.

Required Methods§

Source

fn encode(&self, byte: u8) -> u8

Transform a byte on the way into storage.

Source

fn decode(&self, byte: u8) -> u8

Transform a byte on the way out of storage.

For involution-based codices decode == encode. The two methods are kept separate so that downstream consumers reading the code do not have to remember the invariant.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§