Skip to main content

AlphabetPackExt

Trait AlphabetPackExt 

Source
pub trait AlphabetPackExt: Alphabet {
    const PACK_BITS: usize;
    const CHAR_TO_INDEX: [u8; 128];

    // Provided method
    fn char_to_index(ch: u8) -> Option<usize> { ... }
}
Available on crate feature packed only.
Expand description

An extension trait for Alphabet that provides the pack size and reverse lookup.

This trait defines how many bits are needed to represent each character in the packed representation, and provides a reverse lookup map for O(1) character-to-index conversion.

Required Associated Constants§

Source

const PACK_BITS: usize

Number of bits per character in the packed representation.

Source

const CHAR_TO_INDEX: [u8; 128]

Reverse lookup map: maps ASCII character to its index in the Alphabet. Value is 255 (u8::MAX) for characters not in the Alphabet.

Provided Methods§

Source

fn char_to_index(ch: u8) -> Option<usize>

Get the index of a character in the Alphabet. Returns None if the character is not in the alphabet or not ASCII.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<A: Alphabet + AlphabetExt> AlphabetPackExt for A

Blanket implementation of AlphabetPackExt for all Alphabet types.

This automatically computes:

  • PACK_BITS from the alphabet size.
  • CHAR_TO_INDEX from the symbol list.