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§
Required Methods§
Sourcefn bits_per_fragment(&self) -> u8
fn bits_per_fragment(&self) -> u8
Number of bits needed to store codeword fragment.
Sourcefn fragment_of(&self, code: Self::Codeword, index: u8) -> u8
fn fragment_of(&self, code: Self::Codeword, index: u8) -> u8
Returns index-th fragment of code.
Sourcefn remove_first_fragment_of(&self, code: &mut Self::Codeword) -> bool
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.
Provided Methods§
Sourcefn max_fragment_value(&self) -> u8
fn max_fragment_value(&self) -> u8
Maximum value of fragment.
Sourcefn rev_fragment_of(&self, code: Self::Codeword, index: u8) -> u8
fn rev_fragment_of(&self, code: Self::Codeword, index: u8) -> u8
Returns last index-th fragment of code.
Sourcefn fragments_of(&self, code: Self::Codeword) -> FragmentsIterator<'_, Self> ⓘ
fn fragments_of(&self, code: Self::Codeword) -> FragmentsIterator<'_, Self> ⓘ
Returns iterator over code fragments.
Sourcefn is_code_empty(&self, code: Self::Codeword) -> bool
fn is_code_empty(&self, code: Self::Codeword) -> bool
Returns whether the code is empty (has zero fragments).
Sourcefn first_fragment_of(&self, code: Self::Codeword) -> u8
fn first_fragment_of(&self, code: Self::Codeword) -> u8
Returns the first fragment of the code.
Sourcefn extract_first_fragment_of(&self, code: &mut Self::Codeword) -> Option<u8>
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.
Sourcefn len_of_encoded<'e, Q>(
&self,
encoder: &Self::Encoder<'e>,
to_encode: &Q,
) -> u8
fn len_of_encoded<'e, Q>( &self, encoder: &Self::Encoder<'e>, to_encode: &Q, ) -> u8
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)
Sourcefn fragments_of_encoded<'e, Q>(
&self,
encoder: &Self::Encoder<'e>,
to_encode: &Q,
) -> FragmentsIterator<'_, Self> ⓘ
fn fragments_of_encoded<'e, Q>( &self, encoder: &Self::Encoder<'e>, to_encode: &Q, ) -> FragmentsIterator<'_, Self> ⓘ
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.