Skip to main content

Codes

Enum Codes 

Source
#[non_exhaustive]
pub enum Codes { Unary, Gamma, Delta, Omega, VByteLe, VByteBe, Zeta(usize), Pi(usize), Golomb(u64), ExpGolomb(usize), Rice(usize), }
Expand description

An enum whose variants represent all the available codes.

This enum is kept in sync with implementations in the codes module.

Both Display and FromStr are implemented for this enum in a compatible way, making it possible to store a code as a string in a configuration file and then parse it back.

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

Unary

§

Gamma

§

Delta

§

Omega

§

VByteLe

§

VByteBe

§

Zeta(usize)

§

Pi(usize)

§

Golomb(u64)

§

ExpGolomb(usize)

§

Rice(usize)

Implementations§

Source§

impl Codes

Source

pub const fn canonicalize(self) -> Self

Returns the canonical form of this code.

Some codes are equivalent, in the sense that they are defined differently, but they give rise to the same codewords. Among equivalent codes, there is usually one that is faster to encode and decode, which we call the canonical representative of the equivalence class.

The mapping is:

Source

pub fn read<E: Endianness, CR: CodesRead<E> + ?Sized>( &self, reader: &mut CR, ) -> Result<u64, CR::Error>

Delegates to the DynamicCodeRead implementation.

This inherent method is provided to reduce ambiguity in method resolution.

Source

pub fn write<E: Endianness, CW: CodesWrite<E> + ?Sized>( &self, writer: &mut CW, n: u64, ) -> Result<usize, CW::Error>

Delegates to the DynamicCodeWrite implementation.

This inherent method is provided to reduce ambiguity in method resolution.

Source

pub const fn to_code_const(&self) -> Result<usize, DispatchError>

Converts a code to the constants in the code_consts module used for ConstCode. This is mostly used to verify that the code is supported by ConstCode.

The code is canonicalized before the conversion, so equivalent codes map to the same constant.

§Errors

Returns DispatchError::UnsupportedCode if the (canonicalized) code has no corresponding constant in code_consts.

Source

pub const fn from_code_const(const_code: usize) -> Result<Self, DispatchError>

Converts a value from code_consts to a code.

§Errors

Returns DispatchError::UnsupportedCodeConst if the value does not correspond to any known code constant.

Trait Implementations§

Source§

impl Clone for Codes

Source§

fn clone(&self) -> Codes

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl CodeLen for Codes

Source§

fn len(&self, n: u64) -> usize

Returns the length of the codeword for n.
Source§

impl Debug for Codes

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Codes

Available on crate feature serde only.
Source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for Codes

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl DynamicCodeRead for Codes

Source§

fn read<E: Endianness, CR: CodesRead<E> + ?Sized>( &self, reader: &mut CR, ) -> Result<u64, CR::Error>

Source§

impl DynamicCodeWrite for Codes

Source§

fn write<E: Endianness, CW: CodesWrite<E> + ?Sized>( &self, writer: &mut CW, n: u64, ) -> Result<usize, CW::Error>

Source§

impl FlatType for Codes

Source§

impl FromStr for Codes

Source§

type Err = CodeError

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
Source§

impl Hash for Codes

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl MemDbgImpl for Codes

Source§

fn _mem_dbg_rec_on( &self, _memdbg_writer: &mut impl Write, _memdbg_total_size: usize, _memdbg_max_depth: usize, _memdbg_prefix: &mut String, _memdbg_is_last: bool, _memdbg_flags: DbgFlags, _memdbg_refs: &mut HashSet<usize>, ) -> Result

Source§

fn _mem_dbg_depth_on( &self, writer: &mut impl Write, total_size: usize, max_depth: usize, prefix: &mut String, field_name: Option<&str>, is_last: bool, padded_size: usize, flags: DbgFlags, dbg_refs: &mut HashSet<usize>, ) -> Result<(), Error>

Source§

fn _mem_dbg_depth_on_impl( &self, writer: &mut impl Write, total_size: usize, max_depth: usize, prefix: &mut String, field_name: Option<&str>, is_last: bool, padded_size: usize, flags: DbgFlags, dbg_refs: &mut HashSet<usize>, ref_display: RefDisplay, ) -> Result<(), Error>

Internal implementation for depth display. Read more
Source§

impl MemSize for Codes

Source§

fn mem_size_rec( &self, _memsize_flags: SizeFlags, _memsize_refs: &mut HashMap<usize, usize>, ) -> usize

Recursive implementation that tracks visited references for deduplication. Read more
Source§

fn mem_size(&self, flags: SizeFlags) -> usize

Returns the (recursively computed) overall memory size of the structure in bytes.
Source§

impl PartialEq for Codes

Source§

fn eq(&self, other: &Codes) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Codes

Available on crate feature serde only.
Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<E: Endianness, CR: CodesRead<E> + ?Sized> StaticCodeRead<E, CR> for Codes

Source§

fn read(&self, reader: &mut CR) -> Result<u64, CR::Error>

Source§

impl<E: Endianness, CW: CodesWrite<E> + ?Sized> StaticCodeWrite<E, CW> for Codes

Source§

fn write(&self, writer: &mut CW, n: u64) -> Result<usize, CW::Error>

Source§

impl Copy for Codes

Source§

impl Eq for Codes

Source§

impl StructuralPartialEq for Codes

Auto Trait Implementations§

§

impl Freeze for Codes

§

impl RefUnwindSafe for Codes

§

impl Send for Codes

§

impl Sync for Codes

§

impl Unpin for Codes

§

impl UnsafeUnpin for Codes

§

impl UnwindSafe for Codes

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> MemDbg for T
where T: MemDbgImpl,

Source§

fn mem_dbg(&self, flags: DbgFlags) -> Result<(), Error>

Writes to stderr debug info about the structure memory usage, expanding all levels of nested structures.
Source§

fn mem_dbg_on( &self, writer: &mut impl Write, flags: DbgFlags, ) -> Result<(), Error>

Writes to a core::fmt::Write debug info about the structure memory usage, expanding all levels of nested structures.
Source§

fn mem_dbg_depth(&self, max_depth: usize, flags: DbgFlags) -> Result<(), Error>

Writes to stderr debug info about the structure memory usage as mem_dbg, but expanding only up to max_depth levels of nested structures.
Source§

fn mem_dbg_depth_on( &self, writer: &mut impl Write, max_depth: usize, flags: DbgFlags, ) -> Result<(), Error>

Writes to a core::fmt::Write debug info about the structure memory usage as mem_dbg_on, but expanding only up to max_depth levels of nested structures.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,