Compress

Struct Compress 

Source
pub struct Compress<T: CompressFinite>(/* private fields */);
Expand description

A compressed representation of a value of type T, implemented by storing its index according Finite::index_of using the smallest integer type possible.

§Example

use cantor::*;
use core::mem::size_of_val;

#[derive(Finite, PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Debug)]
enum MyType {
    A,
    B(bool),
    C(bool, bool)
}

let value = MyType::B(false);
assert_eq!(size_of_val(&value), 3);
let compressed = compress(value);
assert_eq!(size_of_val(&compressed), 1);
assert_eq!(value, compressed.expand());

Implementations§

Source§

impl<T: CompressFinite> Compress<T>

Source

pub fn new(value: T) -> Self

Constructs a compressed wrapper over the given value.

Source

pub fn expand(&self) -> T

Gets the expanded form of this compressed value.

Trait Implementations§

Source§

impl<T: CompressFinite> Clone for Compress<T>

Source§

fn clone(&self) -> Self

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<T: CompressFinite> Finite for Compress<T>

Source§

const COUNT: usize = T::COUNT

The number of valid values of this type.
Source§

fn index_of(value: Self) -> usize

Gets a unique integer representation for the given value. This defines a 1-to-1 mapping between values of this type and non-negative integers less than Finite::COUNT.
Source§

fn nth(index: usize) -> Option<Self>

Gets the value with the given index as returned by Finite::index_of, or returns None if the index is out of bounds.
Source§

fn iter() -> FiniteIter<Self>

Iterates over all of the values of this type.
Source§

impl<K: CompressFinite + ArrayFinite<V>, V> Index<Compress<K>> for ArrayMap<K, V>

Source§

type Output = V

The returned type after indexing.
Source§

fn index(&self, index: Compress<K>) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<K: CompressFinite + ArrayFinite<V>, V> IndexMut<Compress<K>> for ArrayMap<K, V>

Source§

fn index_mut(&mut self, index: Compress<K>) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl<T: Ord + CompressFinite> Ord for Compress<T>
where T::Index: Ord,

Source§

fn cmp(&self, other: &Compress<T>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<T: PartialEq + CompressFinite> PartialEq for Compress<T>
where T::Index: PartialEq,

Source§

fn eq(&self, other: &Compress<T>) -> 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<T: PartialOrd + CompressFinite> PartialOrd for Compress<T>
where T::Index: PartialOrd,

Source§

fn partial_cmp(&self, other: &Compress<T>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<T: CompressFinite + BitmapFinite> Set<Compress<T>> for BitmapSet<T>

Source§

fn contains(&self, value: Compress<T>) -> bool

Determines whether the set contains the given value.
Source§

fn include(&mut self, value: Compress<T>)

Ensures that the set includes the given value.
Source§

fn exclude(&mut self, value: Compress<T>)

Ensures that the set excludes the given value.
Source§

impl<T: CompressFinite> Copy for Compress<T>

Source§

impl<T: Eq + CompressFinite> Eq for Compress<T>
where T::Index: Eq,

Source§

impl<T: CompressFinite> StructuralPartialEq for Compress<T>

Auto Trait Implementations§

§

impl<T> Freeze for Compress<T>
where <T as CompressFinite>::Index: Freeze,

§

impl<T> RefUnwindSafe for Compress<T>
where <T as CompressFinite>::Index: RefUnwindSafe,

§

impl<T> Send for Compress<T>
where <T as CompressFinite>::Index: Send,

§

impl<T> Sync for Compress<T>
where <T as CompressFinite>::Index: Sync,

§

impl<T> Unpin for Compress<T>
where <T as CompressFinite>::Index: Unpin,

§

impl<T> UnwindSafe for Compress<T>
where <T as CompressFinite>::Index: UnwindSafe,

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<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, 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.