#enum #associated #constants

no-std associated

A trait for associating enum variants with constants

2 unstable releases

Uses new Rust 2021

0.2.0 Nov 13, 2021
0.1.0 Nov 12, 2021

#4 in #associated

MIT license

3KB

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"

lib.rs:

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

Derive support is enabled with the "derive" feature.

Dependencies

~105KB