pub trait ScribeString {
    // Required method
    fn scribe(&self) -> String;
}
Expand description

Trait for converting an enum to an allocated string. Generally, ScribeCowStr should be preferred over this trait because it avoids unnecessary allocations.

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

This trait can only be used if none of the enum’s variants use ignore.

use enumscribe::ScribeString;

#[derive(ScribeString, PartialEq, Eq, Debug)]
enum Airport {
    #[enumscribe(str = "LHR")]
    Heathrow,
    #[enumscribe(str = "LGW")]
    Gatwick,
    #[enumscribe(other)]
    Other(String),
}

assert_eq!(Airport::Heathrow.scribe(), "LHR".to_owned());
assert_eq!(Airport::Gatwick.scribe(), "LGW".to_owned());
assert_eq!(Airport::Other("STN".to_owned()).scribe(), "STN".to_owned());

Required Methods§

source

fn scribe(&self) -> String

Converts this enum to an allocated String.

When called on a variant marked with #[enumscribe(other)], the variant’s field will be returned. For other variants, the string returned is determined by the #[enumscribe(str = "...")] attribute, or the name of the variant if the attribute is omitted.

Implementors§