VariantName

Trait VariantName 

Source
pub trait VariantName {
    // Required methods
    fn variant_name(&self) -> &'static str;
    fn variant_names() -> &'static [&'static str];
}
Expand description

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§

Source

fn variant_name(&self) -> &'static str

Get identifier of variant

Source

fn variant_names() -> &'static [&'static str]

Get each identifier of all possible variants

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§