Trait enum_map::Enum

source ·
pub trait Enum: Sized {
    type Array<V>: Array;

    // Required methods
    fn from_usize(value: usize) -> Self;
    fn into_usize(self) -> usize;
}
Expand description

Enum mapping type.

This trait is implemented by #[derive(Enum)].

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.

Required Associated Types§

source

type Array<V>: Array

Representation of an enum.

For an enum with four elements it looks like this.

type Array<V> = [V; 4];

Required Methods§

source

fn from_usize(value: usize) -> Self

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

source

fn into_usize(self) -> usize

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

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl Enum for Ordering

§

type Array<V> = [V; 3]

source§

fn from_usize(value: usize) -> Self

source§

fn into_usize(self) -> usize

source§

impl Enum for Infallible

§

type Array<V> = [V; 0]

source§

fn from_usize(_: usize) -> Self

source§

fn into_usize(self) -> usize

source§

impl Enum for bool

§

type Array<V> = [V; 2]

source§

fn from_usize(value: usize) -> Self

source§

fn into_usize(self) -> usize

source§

impl Enum for u8

§

type Array<V> = [V; 256]

source§

fn from_usize(value: usize) -> Self

source§

fn into_usize(self) -> usize

source§

impl Enum for ()

§

type Array<V> = [V; 1]

source§

fn from_usize(value: usize) -> Self

source§

fn into_usize(self) -> usize

Implementors§