Trait Coding

Source
pub trait Coding {
    type Value;
    type Decoder<'d>: Decoder<Value = Self::Value>
       where Self: 'd;
    type Encoder<'e>
       where Self: 'e;
    type Codeword: Copy + Sized + Sync;

Show 15 methods // Required methods fn bits_per_fragment(&self) -> u8; fn decoder(&self) -> Self::Decoder<'_>; fn encoder(&self) -> Self::Encoder<'_>; fn len_of(&self, code: Self::Codeword) -> u8; fn fragment_of(&self, code: Self::Codeword, index: u8) -> u8; fn remove_first_fragment_of(&self, code: &mut Self::Codeword) -> bool; fn code_of<'e, Q>( &self, encoder: &Self::Encoder<'e>, to_encode: &Q, ) -> Self::Codeword where Q: Borrow<Self::Value>; // Provided methods fn max_fragment_value(&self) -> u8 { ... } fn rev_fragment_of(&self, code: Self::Codeword, index: u8) -> u8 { ... } fn fragments_of(&self, code: Self::Codeword) -> FragmentsIterator<'_, Self> { ... } fn is_code_empty(&self, code: Self::Codeword) -> bool { ... } fn first_fragment_of(&self, code: Self::Codeword) -> u8 { ... } fn extract_first_fragment_of(&self, code: &mut Self::Codeword) -> Option<u8> { ... } fn len_of_encoded<'e, Q>( &self, encoder: &Self::Encoder<'e>, to_encode: &Q, ) -> u8 where Q: Borrow<Self::Value> { ... } fn fragments_of_encoded<'e, Q>( &self, encoder: &Self::Encoder<'e>, to_encode: &Q, ) -> FragmentsIterator<'_, Self> where Q: Borrow<Self::Value> { ... }
}
Expand description

A bijection between values and codewords. Codewords are sequences of fragments. Each fragment occupies constant number of bits.

Required Associated Types§

Source

type Value

Type of value.

Source

type Decoder<'d>: Decoder<Value = Self::Value> where Self: 'd

Type of decoder. Decoder decodes a value for code given fragment by fragment.

Source

type Encoder<'e> where Self: 'e

Type of encoder. Encoder maps values to their codes.

Source

type Codeword: Copy + Sized + Sync

Type of codeword.

Required Methods§

Source

fn bits_per_fragment(&self) -> u8

Number of bits needed to store codeword fragment.

Source

fn decoder(&self) -> Self::Decoder<'_>

Returns decoder that allows for decoding a value.

Source

fn encoder(&self) -> Self::Encoder<'_>

Returns a map from values to their codewords.

Source

fn len_of(&self, code: Self::Codeword) -> u8

Returns the length of code in fragments.

Source

fn fragment_of(&self, code: Self::Codeword, index: u8) -> u8

Returns index-th fragment of code.

Source

fn remove_first_fragment_of(&self, code: &mut Self::Codeword) -> bool

Removes the first fragment of the code and returns whether it is empty now.

Source

fn code_of<'e, Q>( &self, encoder: &Self::Encoder<'e>, to_encode: &Q, ) -> Self::Codeword
where Q: Borrow<Self::Value>,

Returns code of the value to_encode.

Provided Methods§

Source

fn max_fragment_value(&self) -> u8

Maximum value of fragment.

Source

fn rev_fragment_of(&self, code: Self::Codeword, index: u8) -> u8

Returns last index-th fragment of code.

Source

fn fragments_of(&self, code: Self::Codeword) -> FragmentsIterator<'_, Self>

Returns iterator over code fragments.

Source

fn is_code_empty(&self, code: Self::Codeword) -> bool

Returns whether the code is empty (has zero fragments).

Source

fn first_fragment_of(&self, code: Self::Codeword) -> u8

Returns the first fragment of the code.

Source

fn extract_first_fragment_of(&self, code: &mut Self::Codeword) -> Option<u8>

Extracts and returns the first fragment of the code or None if the code is already empty.

Source

fn len_of_encoded<'e, Q>( &self, encoder: &Self::Encoder<'e>, to_encode: &Q, ) -> u8
where Q: Borrow<Self::Value>,

Returns the length (number of fragments) of code of the value to_encode. (this is the same value as code(to_encode).fragments, but code_len is faster for some encoders)

Source

fn fragments_of_encoded<'e, Q>( &self, encoder: &Self::Encoder<'e>, to_encode: &Q, ) -> FragmentsIterator<'_, Self>
where Q: Borrow<Self::Value>,

Returns iterator over code fragments.

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.

Implementations on Foreign Types§

Source§

impl<Value: Hash + Eq + Clone> Coding for Coding<Value, BitsPerFragment>

Source§

type Value = Value

Source§

type Decoder<'d> = Decoder<'d, Value> where Value: 'd

Source§

type Encoder<'e> = HashMap<&'e Value, U8Code> where Value: 'e

Source§

type Codeword = U8Code

Source§

fn bits_per_fragment(&self) -> u8

Source§

fn decoder(&self) -> Self::Decoder<'_>

Source§

fn encoder(&self) -> Self::Encoder<'_>

Source§

fn len_of(&self, code: U8Code) -> u8

Source§

fn fragment_of(&self, code: Self::Codeword, index: u8) -> u8

Source§

fn rev_fragment_of(&self, code: Self::Codeword, index: u8) -> u8

Source§

fn remove_first_fragment_of(&self, code: &mut U8Code) -> bool

Source§

fn code_of<'e, Q>( &self, encoder: &Self::Encoder<'e>, to_encode: &Q, ) -> Self::Codeword
where Q: Borrow<Self::Value>,

Implementors§