| Crates.io | indexed_valued_enums_derive |
| lib.rs | indexed_valued_enums_derive |
| version | 2.0.0 |
| created_at | 2024-03-04 10:05:57.946879+00 |
| updated_at | 2025-12-21 21:33:08.323069+00 |
| description | Derive macro for the indexed_valued_enums crate. |
| homepage | |
| repository | https://github.com/JorgeRicoVivas/indexed_valued_enums |
| max_upload_size | |
| id | 1161508 |
| size | 97,126 |
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.