Skip to main content

SymbolCode

Trait SymbolCode 

Source
pub trait SymbolCode:
    Copy
    + Send
    + Sync
    + 'static {
    const CODES: usize;
    const BITS: u32;

    // Required methods
    fn at(index: usize) -> Self;
    fn index(code: Self) -> usize;
    fn index_stream(codes: &[Self], space: usize) -> Option<IndexStream<'_>>;
}
Expand description

A code type whose own order is an enumeration’s order.

u16 and u8, and nothing else: the width is a fact about the artifact’s storage, and the two widths are the two residencies a codec has a use for — two bytes a symbol, and one where the code space fits a byte.

The trait exists so that Arena, Book, Sign and Ternary are one tier at two widths rather than two tiers with one decode: the table read, the bit fields, the enumeration, and the canonicalization are written once, against these methods.

Required Associated Constants§

Source

const CODES: usize

How many distinct codes the type holds.

Source

const BITS: u32

The type’s own width in bits, for the shift guard a bit-field decode totals against: a position past it reads as a clear field, at either width.

Required Methods§

Source

fn at(index: usize) -> Self

The code at index in the type’s own order. Total below CODES.

Source

fn index(code: Self) -> usize

Where code sits in the type’s own order.

Source

fn index_stream(codes: &[Self], space: usize) -> Option<IndexStream<'_>>

The stored code stream read as the index stream it already is, when it is one.

index_of is % space at every tier here, which is & (space - 1) exactly when the space is a power of two — and then the stored code, masked, is the index, at either width, and the traversal borrows it. At any other entry count the two differ and the traversal builds the stream, at the same bytes. The variant names the width: a byte stream answers IndexStream::U8, and the gather dispatches on it once.

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementations on Foreign Types§

Source§

impl SymbolCode for u8

Source§

const CODES: usize

Source§

const BITS: u32 = u8::BITS

Source§

fn at(index: usize) -> Self

Source§

fn index(code: Self) -> usize

Source§

fn index_stream(codes: &[Self], space: usize) -> Option<IndexStream<'_>>

Source§

impl SymbolCode for u16

Source§

const CODES: usize = U16_CODES

Source§

const BITS: u32 = u16::BITS

Source§

fn at(index: usize) -> Self

Source§

fn index(code: Self) -> usize

Source§

fn index_stream(codes: &[Self], space: usize) -> Option<IndexStream<'_>>

Implementors§