[][src]Crate enum_like

This crate provides the EnumLike trait, which defines a mapping from a given type to usize.

This is similar to std::mem::discriminant, however it has a few differences. First of all, all the values are consecutive starting from zero. This means that if an enum has 10 variants, the discriminant will always be lower than 10. If a field has an explicit discriminant, that value is ignored: in enum { A = 100 }, A will have the value of 0. And most importantly, this trait allows to create an instance of the type from the usize, because the enum data, if present, is also encoded in the discriminant (if possible). For example:

enum ABC { A, B, C }
enum DEF { D, E, F }
enum AD { A(ABC), D(DEF) }

The AD enum has 2 variants, but since each of these variants is an enum with 3 variants, the AD::values().count() will return 6 instead of 2.



Packs an EnumLike value into a u8, if possible


Packs an EnumLike value into a u16, if possible


Iterator over the values (variants) of T



The EnumLike trait specifies how a type will be stored inside the EnumVec.


Helper trait to iterate over all the possible values of an enum. Note: you don't need to implement this trait, it is provided by EnumLike.