pub trait ScribeStaticStr {
    // Required method
    fn scribe(&self) -> &'static str;
}
Expand description

Trait for converting an enum to a static string slice.

Like all of the traits provided by enumscribe, this should not be implemented manually; use #[derive(ScribeStaticStr)] provided by the enumscribe_derive crate instead.

When deriving this trait, you may specify the string that a particular variant should be converted to by annotating it with #[enumscribe(str = "foo")]. If this is omitted, the name of the variant will be used instead.

This trait can only be used if none of the enum’s variants use ignore or other. If you have variants that use ignore, use TryScribeStaticStr instead. If you have variants that use other, use ScribeCowStr. If you have variants that use both, use TryScribeCowStr.

use enumscribe::ScribeStaticStr;

#[derive(ScribeStaticStr, PartialEq, Eq, Debug)]
enum Airport {
    #[enumscribe(str = "LHR")]
    Heathrow,
    #[enumscribe(str = "LGW")]
    Gatwick,
    UnnamedAirport,
}

assert_eq!(Airport::Heathrow.scribe(), "LHR");
assert_eq!(Airport::Gatwick.scribe(), "LGW");
assert_eq!(Airport::UnnamedAirport.scribe(), "UnnamedAirport");

Required Methods§

source

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

Converts this enum to a &'static str.

The string returned for a particular variant is determined by the #[enumscribe(str = "...")] attribute, or the name of the variant if the attribute is omitted.

Implementors§