Enum

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

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§