associated 0.2.0

A trait for associating enum variants with constants
Documentation
  • Coverage
  • 71.43%
    5 out of 7 items documented0 out of 4 items with examples
  • Size
  • Source code size: 4.14 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.06 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 9s Average build duration of successful builds.
  • all releases: 9s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • ZacJW/associated
    2 0 2
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • ZacJW

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"