Trait Linearize

Source
pub unsafe trait Linearize {
    type Storage<T>: Storage<Self, T>;
    type CopyStorage<T>: CopyStorage<Self, T>
       where T: Copy;

    const LENGTH: usize;

    // Required methods
    fn linearize(&self) -> usize;
    unsafe fn from_linear_unchecked(linear: usize) -> Self
       where Self: Sized;
}
Expand description

Types whose values can be enumerated.

Types that implement this trait define a bijection between themselves and an interval of the natural numbers.

§Safety

Note that the bijection implies that a roundtrip through linearize | from_linear_unchecked must return a value that is, for all intents and purposes, indistinguishable from the original value. The details of this depend on Self.

Required Associated Constants§

Source

const LENGTH: usize

The cardinality of this type.

Required Associated Types§

Source

type Storage<T>: Storage<Self, T>

[T; Self::LENGTH]

This type exists due to a limitation of the rust type system. In a future version of this crate, all uses of it will be replaced by [T; Self::LENGTH].

Source

type CopyStorage<T>: CopyStorage<Self, T> where T: Copy

[T; Self::LENGTH]

This type exists due to a limitation of the rust type system. In a future version of this crate, all uses of it will be replaced by [T; Self::LENGTH].

Required Methods§

Source

fn linearize(&self) -> usize

Maps this value to the natural numbers.

This function is a bijection to the interval [0, Self::LENGTH).

Source

unsafe fn from_linear_unchecked(linear: usize) -> Self
where Self: Sized,

The inverse of the linearize function.

§Safety

linear must be less than Self::LENGTH.

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.

Implementations on Foreign Types§

Source§

impl Linearize for Ordering

Source§

const LENGTH: usize = 3usize

Source§

type Storage<T> = [T; 3]

Source§

type CopyStorage<T> = [T; 3] where T: Copy

Source§

fn linearize(&self) -> usize

Source§

unsafe fn from_linear_unchecked(linear: usize) -> Self
where Self: Sized,

Source§

impl Linearize for Infallible

Source§

const LENGTH: usize = 0usize

Source§

type Storage<T> = [T; 0]

Source§

type CopyStorage<T> = [T; 0] where T: Copy

Source§

fn linearize(&self) -> usize

Source§

unsafe fn from_linear_unchecked(_linear: usize) -> Self
where Self: Sized,

Source§

impl Linearize for Alignment

Source§

const LENGTH: usize = 3usize

Source§

type Storage<T> = [T; 3]

Source§

type CopyStorage<T> = [T; 3] where T: Copy

Source§

fn linearize(&self) -> usize

Source§

unsafe fn from_linear_unchecked(linear: usize) -> Self
where Self: Sized,

Source§

impl Linearize for FpCategory

Source§

const LENGTH: usize = 5usize

Source§

type Storage<T> = [T; 5]

Source§

type CopyStorage<T> = [T; 5] where T: Copy

Source§

fn linearize(&self) -> usize

Source§

unsafe fn from_linear_unchecked(linear: usize) -> Self
where Self: Sized,

Source§

impl Linearize for Shutdown

Source§

const LENGTH: usize = 3usize

Source§

type Storage<T> = [T; 3]

Source§

type CopyStorage<T> = [T; 3] where T: Copy

Source§

fn linearize(&self) -> usize

Source§

unsafe fn from_linear_unchecked(linear: usize) -> Self
where Self: Sized,

Source§

impl Linearize for bool

Source§

const LENGTH: usize = 2usize

Source§

type Storage<T> = [T; 2]

Source§

type CopyStorage<T> = [T; 2] where T: Copy

Source§

fn linearize(&self) -> usize

Source§

unsafe fn from_linear_unchecked(linear: usize) -> Self
where Self: Sized,

Source§

impl Linearize for i8

Source§

const LENGTH: usize = 256usize

Source§

type Storage<T> = [T; 256]

Source§

type CopyStorage<T> = [T; 256] where T: Copy

Source§

fn linearize(&self) -> usize

Source§

unsafe fn from_linear_unchecked(linear: usize) -> Self

Source§

impl Linearize for i16

Source§

const LENGTH: usize = 65_536usize

Source§

type Storage<T> = [T; 65536]

Source§

type CopyStorage<T> = [T; 65536] where T: Copy

Source§

fn linearize(&self) -> usize

Source§

unsafe fn from_linear_unchecked(linear: usize) -> Self

Source§

impl Linearize for i32

Source§

const LENGTH: usize = 4_294_967_296usize

Source§

type Storage<T> = [T; 4294967296]

Source§

type CopyStorage<T> = [T; 4294967296] where T: Copy

Source§

fn linearize(&self) -> usize

Source§

unsafe fn from_linear_unchecked(linear: usize) -> Self

Source§

impl Linearize for u8

Source§

const LENGTH: usize = 256usize

Source§

type Storage<T> = [T; 256]

Source§

type CopyStorage<T> = [T; 256] where T: Copy

Source§

fn linearize(&self) -> usize

Source§

unsafe fn from_linear_unchecked(linear: usize) -> Self
where Self: Sized,

Source§

impl Linearize for u16

Source§

const LENGTH: usize = 65_536usize

Source§

type Storage<T> = [T; 65536]

Source§

type CopyStorage<T> = [T; 65536] where T: Copy

Source§

fn linearize(&self) -> usize

Source§

unsafe fn from_linear_unchecked(linear: usize) -> Self
where Self: Sized,

Source§

impl Linearize for u32

Source§

const LENGTH: usize = 4_294_967_296usize

Source§

type Storage<T> = [T; 4294967296]

Source§

type CopyStorage<T> = [T; 4294967296] where T: Copy

Source§

fn linearize(&self) -> usize

Source§

unsafe fn from_linear_unchecked(linear: usize) -> Self
where Self: Sized,

Source§

impl Linearize for ()

Source§

const LENGTH: usize = 1usize

Source§

type Storage<T> = [T; 1]

Source§

type CopyStorage<T> = [T; 1] where T: Copy

Source§

fn linearize(&self) -> usize

Source§

unsafe fn from_linear_unchecked(_linear: usize) -> Self
where Self: Sized,

Source§

impl Linearize for PhantomPinned

Source§

const LENGTH: usize = 1usize

Source§

type Storage<T> = [T; 1]

Source§

type CopyStorage<T> = [T; 1] where T: Copy

Source§

fn linearize(&self) -> usize

Source§

unsafe fn from_linear_unchecked(_linear: usize) -> Self
where Self: Sized,

Source§

impl<X> Linearize for PhantomData<X>
where X: ?Sized,

Source§

const LENGTH: usize = 1usize

Source§

type Storage<T> = [T; 1]

Source§

type CopyStorage<T> = [T; 1] where T: Copy

Source§

fn linearize(&self) -> usize

Source§

unsafe fn from_linear_unchecked(_linear: usize) -> Self
where Self: Sized,

Implementors§