Skip to main content

Representation

Trait Representation 

Source
pub trait Representation<const NBITS: usize> {
    type Domain: Iterator<Item = i64>;

    // Required methods
    fn encode(value: i64) -> Result<u8, EncodingError>;
    fn encode_unchecked(value: i64) -> u8;
    fn decode(raw: u8) -> i64;
    fn check(value: i64) -> bool;
    fn domain() -> Self::Domain;
}
Expand description

Representation of NBITS bit numbers in the associated domain.

Required Associated Types§

Source

type Domain: Iterator<Item = i64>

The type of the domain accepted by this representation.

Required Methods§

Source

fn encode(value: i64) -> Result<u8, EncodingError>

Encode value into the lower order bits of a byte. Returns the encoded value on success, or an EncodingError if the value is unencodable.

Source

fn encode_unchecked(value: i64) -> u8

Encode value into the lower order bits of a byte without checking if value is encodable. This function is not marked as unsafe because in-and-of itself, it won’t cause memory safety issues.

This may panic in debug mode when value is outside of this representation’s domain.

Source

fn decode(raw: u8) -> i64

Decode a previously encoded value. The result will be in the range [Self::MIN, Self::MAX].

§Panics

May panic in debug builds if raw is not a valid pattern emitted by encode.

Source

fn check(value: i64) -> bool

Check whether or not the argument is in the domain.

Source

fn domain() -> Self::Domain

Return an iterator over the domain of representable values.

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§