Trait variant_name::VariantName[][src]

pub trait VariantName {
    fn variant_name(&self) -> &'static str;
fn variant_names() -> &'static [&'static str]; }

Trait to uniquely identify the variant of an enumeration.

Similar to Discriminant except that it can easily printed and is user-defined. This trait can entirely be derived with the variant_name_derive crate.

Example

#[macro_use] extern crate variant_name_derive;
extern crate variant_name;

use variant_name::VariantName;

#[derive(VariantName)]
enum EnumTest {
    VariantA,
    VariantB { a: usize },
    VariantC(usize),
}

Required Methods

Get identifier of variant

Get each identifier of all possible variants

Implementors