Derive Macro enumscribe_derive::ScribeStaticStr [−][src]
#[derive(ScribeStaticStr)] { // Attributes available to this derive: #[enumscribe] }
Expand description
Derives enumscribe::ScribeStaticStr
for an enum. This allows the enum to be converted to
a &'static str
using the scribe()
method.
You may annotate variants with #[enumscribe(str = "foo")]
to specify what string the variant
should be converted to (replacing "foo"
with a string of your choice). If this is omitted,
the name of the variant will be used instead. Using the same string for two variants of the
same enum will cause a compile-time error.
Other derive macros in this crate allow you to use attributes like #[enumscribe(other)]
and #[enumscribe(ignore)]
, where other
allows you to specify a variant that should be used
to store strings that could not be matched to any other variant, and ignore
lets you tell
enumscribe
not to consider a particular variant when deriving traits. However, using either
of these attributes when deriving ScribeStaticStr
will cause a compile-time error; if these
attributes are used, then there are some cases where it would be impossible to return
a meaningful &'static str
.
If you want to use #[enumscribe(other)]
, try deriving
ScribeCowStr
instead.
If you want to use #[enumscribe(ignore)]
, try deriving
TryScribeStaticStr
instead.
If you want to use both, try deriving
TryScribeCowStr
instead.