StaticIndex

Trait StaticIndex 

Source
pub trait StaticIndex: 'static + Index<Size = ()> {
    const ALL: &'static [Self];

    // Required method
    fn to_usize(self) -> usize;

    // Provided method
    fn from_usize(index: usize) -> Self { ... }
}
Expand description

Implemented by types that can be used as an index for an Array and where the size of the Array is a compile-time constant.

Required Associated Constants§

Source

const ALL: &'static [Self]

The (compile-time constant) complete list of Selfs.

Required Methods§

Source

fn to_usize(self) -> usize

Returns the index in ALL of Self.

Provided Methods§

Source

fn from_usize(index: usize) -> Self

Equivalent to, but often more efficient than, ALL[index].

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.

Implementations on Foreign Types§

Source§

impl StaticIndex for bool

Source§

const ALL: &'static [Self]

Source§

fn to_usize(self) -> usize

Source§

fn from_usize(index: usize) -> Self

Source§

impl StaticIndex for ()

Source§

const ALL: &'static [Self]

Source§

fn to_usize(self) -> usize

Source§

fn from_usize(_: usize) -> Self

Implementors§