Crate enum_like[][src]

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.

Structs

PackedU8

Packs an EnumLike value into a u8, if possible

PackedU16

Packs an EnumLike value into a u16, if possible

Values

Iterator over the values (variants) of T

Traits

EnumLike

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

EnumValues

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.