[−][src]Trait enum_map::Enum
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
Representation of an enum map for type V
, usually an array.
Associated Constants
const POSSIBLE_VALUES: usize
Number of possible states the type can have.
Required methods
fn slice(array: &Self::Array) -> &[V]
Gets a slice from an array type.
fn slice_mut(array: &mut Self::Array) -> &mut [V]
Gets a mutable slice from an array type.
fn from_usize(value: usize) -> Self
Takes an usize, and returns an element matching to_usize
function.
fn to_usize(self) -> usize
Returns an unique identifier for a value within range of 0..POSSIBLE_VALUES
.
fn from_function<F>(f: F) -> Self::Array where
F: FnMut(Self) -> V,
F: FnMut(Self) -> V,
Creates an array using a function called for each argument.
Implementors
impl<T> Enum<T> for bool
[src]
type Array = [T; 2]
const POSSIBLE_VALUES: usize
[src]
fn slice(array: &[T; 2]) -> &[T]
[src]
fn slice_mut(array: &mut [T; 2]) -> &mut [T]
[src]
fn from_usize(value: usize) -> bool
[src]
fn to_usize(self) -> usize
[src]
fn from_function<F>(f: F) -> [T; 2] where
F: FnMut(bool) -> T,
[src]
F: FnMut(bool) -> T,
impl<T> Enum<T> for u8
[src]
type Array = [T; 256]
const POSSIBLE_VALUES: usize
[src]
fn slice(array: &[T; 256]) -> &[T]
[src]
fn slice_mut(array: &mut [T; 256]) -> &mut [T]
[src]
fn from_usize(value: usize) -> u8
[src]
fn to_usize(self) -> usize
[src]
fn from_function<F>(f: F) -> [T; 256] where
F: FnMut(u8) -> T,
[src]
F: FnMut(u8) -> T,