Skip to main content

IndexedEnum

Trait IndexedEnum 

Source
pub trait IndexedEnum:
    Sealed
    + Sized
    + 'static {
    const VARIANTS: &[Self];

    // Required method
    fn as_index(&self) -> usize;
}
Expand description

Trait for enums that have fixed indexed variants.

Required Associated Constants§

Source

const VARIANTS: &[Self]

A slice containing all the variants in index order.

The exact value is subject to change in any future release.

Required Methods§

Source

fn as_index(&self) -> usize

Returns this variant’s unique zero-based index.

The index satisfies 0 <= self.as_index() < Self::VARIANTS.len().

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§