#enums #constants

no-std associated

A trait for associating enum variants with constants

2 unstable releases

0.2.0 Nov 13, 2021
0.1.0 Nov 12, 2021

#332 in No standard library


Used in razer_driver_rs

MIT license

4KB

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

~230KB