pub trait Enumeration: TryFrom<Self::Index, Error = OutOfRangeError<Self>> + Into<Self::Index> + Clone + Copy + Debug + Hash + PartialEq + Eq + PartialOrd + Ord + 'static where
    Self::AssociatedValueType: 'static + Debug,
    Self::Index: Debug + Display
{ type Index; type AssociatedValueType; const VARIANT_COUNT: Self::Index; const DEFAULT_VARIANT_ASSOCIATED_VALUE: Option<Self::AssociatedValueType>; fn value(&self) -> &'static Self::AssociatedValueType; fn variant(index: Self::Index) -> Result<Self, Self::Error> { ... } fn to_index(self) -> Self::Index { ... } }
Expand description

A trait to extend enum.

You should not implement this directly, instead use enumerate!. The rest of the library assumes the constants are correct.

This trait provides support for

  • implementation for common traits (Clone, Copy, Hash, etc.)
  • getting number of variants through constant Self::VARIANT_COUNT
  • casting between index (of type Self::Index) and enumeration
  • attaching a constant value to each of the variants

Required Associated Types

The type of index this enumeration can cast to.

The type of associated constant value of the variants of this enumeration.

Required Associated Constants

The number of variants of this enumeration.

Default for associated constant value.

Required Methods

Get the reference to the static associated constant value of the variant or the default constant value Self::DEFAULT_VARIANT_ASSOCIATED_VALUE.

Provided Methods

Cast index to the respective enumeration.

Errors

If the index is out of range (zero to Self::VARIANT_COUNT (exclusive)), this function will return OutOfRangeError

Cast this enumeration to respective index.

Implementors