[][src]Trait strum::EnumMessage

pub trait EnumMessage {
    fn get_message(&self) -> Option<&str>;
fn get_detailed_message(&self) -> Option<&str>;
fn get_serializations(&self) -> &[&str]; }

Associates additional pieces of information with an Enum. This can be autoimplemented by deriving EnumMessage and annotating your variants with `#[strum(message="...")].

Example

// You need to bring the type into scope to use it!!!
use strum::EnumMessage;

#[derive(PartialEq, Eq, Debug, EnumMessage)]
enum Pet {
    #[strum(message="I have a dog")]
    #[strum(detailed_message="My dog's name is Spots")]
    Dog,
    #[strum(message="I don't have a cat")]
    Cat,
}

fn main() {
    let my_pet = Pet::Dog;
    assert_eq!("I have a dog", my_pet.get_message().unwrap());
}

Required methods

fn get_message(&self) -> Option<&str>

fn get_detailed_message(&self) -> Option<&str>

fn get_serializations(&self) -> &[&str]

Loading content...

Implementors

Loading content...