[][src]Trait strum::EnumProperty

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

    pub fn get_int(&self, _prop: &str) -> Option<usize> { ... }
pub fn get_bool(&self, _prop: &str) -> Option<bool> { ... } }

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

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

Loading content...

Provided methods

pub fn get_int(&self, _prop: &str) -> Option<usize>[src]

pub fn get_bool(&self, _prop: &str) -> Option<bool>[src]

Loading content...

Implementors

Loading content...