Trait enum_map::Enum[][src]

pub trait Enum<V>: Sized {
    type Array: Array<V>;
    fn from_usize(value: usize) -> Self;
fn into_usize(self) -> usize; }
Expand description

Enum mapping type

This trait is internally used by #[derive(Enum)]. Enum<T> is implemented by any enum type where V is a generic type representing a value. The purpose of this generic type is to allow providing a value type for arrays, as Rust currently does not support higher kinded types.

This trait is also implemented by bool and u8. While u8 is strictly speaking not an actual enum, there are good reasons to consider it like one, as array of u8 keys is a relatively common pattern.

Associated Types

type Array: Array<V>[src]

Expand description

Representation of an enum map for type V.

Required methods

fn from_usize(value: usize) -> Self[src]

Expand description

Takes an usize, and returns an element matching into_usize function.

fn into_usize(self) -> usize[src]

Expand description

Returns an unique identifier for a value within range of 0..Array::LENGTH.

Implementations on Foreign Types

impl<T> Enum<T> for bool[src]

type Array = [T; 2]

fn from_usize(value: usize) -> Self[src]

fn into_usize(self) -> usize[src]

impl<T> Enum<T> for u8[src]

type Array = [T; 256]

fn from_usize(value: usize) -> Self[src]

fn into_usize(self) -> usize[src]

impl<T> Enum<T> for Infallible[src]

type Array = [T; 0]

fn from_usize(_: usize) -> Self[src]

fn into_usize(self) -> usize[src]

Implementors