Trait strum::EnumMessage

source ·
pub trait EnumMessage {
    // Required methods
    fn get_message(&self) -> Option<&'static str>;
    fn get_detailed_message(&self) -> Option<&'static str>;
    fn get_documentation(&self) -> Option<&'static str>;
    fn get_serializations(&self) -> &'static [&'static str];
}
Expand description

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,
    /// I am documented.
    #[strum(message="I don't have a cat")]
    Cat,
}

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

Required Methods§

source

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

source

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

source

fn get_documentation(&self) -> Option<&'static str>

Get the doc comment associated with a variant if it exists.

source

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

Implementors§