associated

Crates.ioassociated
lib.rsassociated
version0.2.0
sourcesrc
created_at2021-11-12 21:46:38.620357
updated_at2021-11-13 23:25:15.655526
descriptionA trait for associating enum variants with constants
homepage
repositoryhttps://github.com/ZacJW/associated
max_upload_size
id481146
size3,249
(ZacJW)

documentation

README

associated

A trait to associate enum variants with constants. See associated-derive for deriving this trait automatically.

Derive support is enabled with the "derive" feature.

Example

#[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"
Commit count: 11

cargo fmt