enum_like 0.2.0

A trait to treat any type as an enum. If a type has a reasonably small number of variants, for example a `struct A(bool, bool)` which has 4 variants, this trait provides a 1-to-1 mapping from type value to a discriminant value. It also provides an iterator over all the possible values. This crate is mainly meant to be used along with [enum_like_derive](https://crates.io/crates/enum_like_derive) and [enum_vec](https://crates.io/crates/enum_vec) .
Documentation

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.