enum_collections/enumerated.rs
1/// Provides means to map enum values to positions in arrays backing an EnumMap/EnumTable.
2/// Not intended to be implemented by hand. Deriving it with `#[derive(Enumerated)]`
3/// attribute macro is preferred.
4///
5/// ```
6/// use enum_collections::Enumerated;
7/// #[derive(Enumerated)]
8/// enum Letter {
9/// A,
10/// B,
11/// }
12///
13/// assert_eq!(Letter::SIZE, 2);
14/// ```
15#[doc(hidden)]
16pub trait Enumerated: Sized + 'static {
17 /// Maps an enum to a unique position in an array.
18 fn position(self) -> usize;
19 const SIZE: usize = 0;
20 /// All variants of the enum. Sorted by their discriminants ASC.
21 #[cfg(feature = "variants")]
22 const VARIANTS: &'static [Self];
23}