Crates.io | associated |
lib.rs | associated |
version | 0.2.0 |
source | src |
created_at | 2021-11-12 21:46:38.620357 |
updated_at | 2021-11-13 23:25:15.655526 |
description | A trait for associating enum variants with constants |
homepage | |
repository | https://github.com/ZacJW/associated |
max_upload_size | |
id | 481146 |
size | 3,249 |
A trait to associate enum variants with constants. See associated-derive for deriving this trait automatically.
Derive support is enabled with the "derive"
feature.
#[derive(Associated)]
#[associated(Type = &'static str)]
enum Phonetic {
#[assoc_const("Alpha")] Alpha,
#[assoc(&"Bravo")] // #[assoc] requires an expression of type &'static Type
Bravo = 3 // supports explicit enum discriminants
// ...
}
Phonetic::Alpha.get_associated() // returns a static lifetime reference to "Alpha"