strum

Trait EnumProperty

Source
pub trait EnumProperty {
    // Required method
    fn get_str(&self, prop: &str) -> Option<&'static str>;

    // Provided methods
    fn get_int(&self, _prop: &str) -> Option<usize> { ... }
    fn get_bool(&self, _prop: &str) -> Option<bool> { ... }
}
Expand description

EnumProperty is a trait that makes it possible to store additional information with enum variants. This trait is designed to be used with the macro of the same name in the strum_macros crate. Currently, the only string literals are supported in attributes, the other methods will be implemented as additional attribute types become stabilized.

§Example

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

#[derive(PartialEq, Eq, Debug, EnumProperty)]
enum Class {
    #[strum(props(Teacher="Ms.Frizzle", Room="201"))]
    History,
    #[strum(props(Teacher="Mr.Smith"))]
    #[strum(props(Room="103"))]
    Mathematics,
    #[strum(props(Time="2:30"))]
    Science,
}

let history = Class::History;
assert_eq!("Ms.Frizzle", history.get_str("Teacher").unwrap());

Required Methods§

Source

fn get_str(&self, prop: &str) -> Option<&'static str>

Provided Methods§

Source

fn get_int(&self, _prop: &str) -> Option<usize>

Source

fn get_bool(&self, _prop: &str) -> Option<bool>

Implementors§