associated 0.1.0

A trait for associating enum variants with constants
Documentation

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, which is enabled by default.

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"