pub trait Enum<V> {
type Array;
const POSSIBLE_VALUES: usize;
fn slice(array: &Self::Array) -> &[V]ⓘNotable traits for &'_ [u8]impl Read for &'_ [u8]impl Write for &'_ mut [u8]
;
fn slice_mut(array: &mut Self::Array) -> &mut [V]ⓘNotable traits for &'_ [u8]impl Read for &'_ [u8]impl Write for &'_ mut [u8]
;
fn from_usize(value: usize) -> Self;
fn to_usize(self) -> usize;
fn from_function<F>(f: F) -> Self::Array
where
F: FnMut(Self) -> V;
}
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
Associated Constants
const POSSIBLE_VALUES: usize
const POSSIBLE_VALUES: usize
Number of possible states the type can have.
Required methods
Gets a slice from an array type.
Gets a mutable slice from an array type.
fn from_usize(value: usize) -> Self
fn from_usize(value: usize) -> Self
Takes an usize, and returns an element matching to_usize
function.
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,
fn from_function<F>(f: F) -> Self::Array where
F: FnMut(Self) -> V,
Creates an array using a function called for each argument.