Trait enumap::Enum

source ·
pub trait Enum<const LENGTH: usize>: Copy + Sized {
    const LENGTH: usize = LENGTH;

    // Required methods
    fn from_index(index: usize) -> Option<Self>;
    fn to_index(value: Self) -> usize;
}
Expand description

Enum type, usually implemented using the enumap macro.

Any enumeration used by EnumMap must implement this trait.

Failures in implementing the trait will not result in undefined behaviour but may result in panics and invalid results.

Provided Associated Constants§

source

const LENGTH: usize = LENGTH

Length of the enum.

Equivalent to the const generic length.

Required Methods§

source

fn from_index(index: usize) -> Option<Self>

Converts an index to an enum variant.

Passed index must be in range 0..LENGTH.

source

fn to_index(value: Self) -> usize

Converts an enum variant to an index.

Returned index must be in range 0..LENGTH.

Object Safety§

This trait is not object safe.

Implementors§