Skip to main content

Enum

Trait 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.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl Enum for ()

Source§

type Array<V> = [V; 1]

Source§

fn from_usize(value: usize) -> Self

Source§

fn into_usize(self) -> usize

Source§

impl Enum for Infallible

Source§

impl Enum for Ordering

Source§

type Array<V> = [V; 3]

Source§

fn from_usize(value: usize) -> Self

Source§

fn into_usize(self) -> usize

Source§

impl Enum for bool

Source§

type Array<V> = [V; 2]

Source§

fn from_usize(value: usize) -> Self

Source§

fn into_usize(self) -> usize

Source§

impl Enum for u8

Implementors§