pub trait Indexed {
const VARIANTS_LEN: usize;
const VARIANTS_NAMES: &'static [&'static str];
}Expand description
Allows getting an index from an enum’s variant to a usize, and also get the same variant from said index, for example, having the following implementation:
#[repr(usize)]
enum Number{ First, Second, Third }
impl indexed_valued_enums::indexed_enum::Indexed for Number{
const VARIANTS_LEN: usize = 3;
const VARIANTS_NAMES: &'static [&'static str] = &["First", "Second", "Third"];
}
impl indexed_valued_enums::indexed_enum::IndexedWithVariant for Number{
const VARIANTS: &'static [Self] = &[Number::First, Number::Second, Number::Third];
}
Calling variant_index on every enum produces [First->0, Second->1, Third->2].
Calling on from_variant_index over the enums would produce [0->First, 1->Second, 2->Third].
Note this documentation it’s solely informational, it is dis-recommended to implement this trait manually, but using the derive macro [crate::legacy::valued_enum::Valued] or the declarative macro [crate::create_indexed_valued_enum] instead.
Required Associated Constants§
Sourceconst VARIANTS_LEN: usize
const VARIANTS_LEN: usize
Number of variants.
IndexedWithVariant::VARIANTS and Self::VARIANTS_NAMES should have the same length as this constant.
Sourceconst VARIANTS_NAMES: &'static [&'static str]
const VARIANTS_NAMES: &'static [&'static str]
Array with the name of every variant
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementors§
Source§impl Indexed for indexed_valued_enums::examples::example_1_basic_enum_and_values::Planet
Available on crate feature docs only.
impl Indexed for indexed_valued_enums::examples::example_1_basic_enum_and_values::Planet
docs only.