| Crates.io | indexed_valued_enums |
| lib.rs | indexed_valued_enums |
| version | 2.0.0 |
| created_at | 2023-11-29 15:24:38.174157+00 |
| updated_at | 2025-12-21 21:33:10.775696+00 |
| description | Create enums resolving into values, and get their variants back through their values, their discriminant or their name; inspired by Java. |
| homepage | |
| repository | https://github.com/JorgeRicoVivas/indexed_valued_enums |
| max_upload_size | |
| id | 1053210 |
| size | 71,803 |
This crate makes easier to associate values to variant's of an enum while not incurring a slowdown in runtime, and also to get the variant back from the value.
This crate gives you the following derive macros for this:
EnumIndexed: This gives you functions for getting the index and name of every variant, and get the variant
back from either the index or the name. This is done by implementing the Indexed, IndexedWithVariant, and
Fieldless traits, and it gives you the following functions:
const fn variant_index(&self) -> usize, this is O(1).const fn from_variant_index(index: usize) -> Option<Self>, this is O(1).const fn variant_name(&self) -> &'static str, this is O(1).const fn from_variant_name(search: &str) -> Option<Self>, this is O(N).EnumValued: This macro turns functions with the signature fn *function_name*(&self) -> *TypeOfValue* into
O(1) functions. It also gives you a fn from_*name of function*(value: &*associated type*) -> Option<Self>
function, which is O(N).
EnumValuedFromCSV: Similar to EnumValued, but you can specify the values of the variants in a CSV file.
You can find a full description and examples inside the documentation of each of these macros.
Note for users of 1.X.X: The 2.X.X version offers no backward compatibility with 1.X.X, as 1.X.X was
arduous to use for end-users.