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§
Trait Implementations§
Source§impl<T: CompressFinite> Finite for Compress<T>
impl<T: CompressFinite> Finite for Compress<T>
Source§fn index_of(value: Self) -> usize
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>
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> ⓘ
fn iter() -> FiniteIter<Self> ⓘ
Iterates over all of the values of this type.
Source§impl<T: Ord + CompressFinite> Ord for Compress<T>where
T::Index: Ord,
impl<T: Ord + CompressFinite> Ord for Compress<T>where
T::Index: Ord,
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
Source§impl<T: PartialOrd + CompressFinite> PartialOrd for Compress<T>where
T::Index: PartialOrd,
impl<T: PartialOrd + CompressFinite> PartialOrd for Compress<T>where
T::Index: PartialOrd,
impl<T: CompressFinite> Copy for Compress<T>
impl<T: Eq + CompressFinite> Eq for Compress<T>where
T::Index: Eq,
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more