Crate plain_enum [−] [src]
This crate offers some tools to deal with static enums. It offers a way to declare a simple
enum, which then offers e.g. values()
which can be used to iterate over the values of the enum.
In addition, it offers a type EnumMap
which is an array-backed map from enum values to some type.
It offers a macro plain_enum_mod
which declares an own module which contains a simple enum
and the associated functionality:
mod examples_not_to_be_used_by_clients { #[macro_use] use plain_enum::*; plain_enum_mod!{example_mod_name, ExampleEnum { V1, V2, SomeOtherValue, LastValue, // note trailing comma }} fn do_some_stuff() { let map = ExampleEnum::map_from_fn(|example| // create a map from ExampleEnum to usize example.to_usize() + 1 // enum values convertible to usize ); for ex in ExampleEnum::values() { // iterating over the enum's values assert_eq!(map[ex], ex.to_usize() + 1); } } }
Internally, the macro generates a simple enum whose numeric values start counting at 0.
Modules
examples_not_to_be_used_by_clients |
A sample module showing the capabilities of this crate. Do not use it or rely on it. |
Macros
acc_arr | |
enum_seq_len | |
plain_enum_mod |
Traits
TEnumMapType |
Trait used to associated enum with EnumMap. |
TPlainEnum |
This trait is implemented by enums declared via the |
Type Definitions
EnumMap |