Derive Macro enumscribe_derive::ScribeCowStr [−][src]
#[derive(ScribeCowStr)] { // Attributes available to this derive: #[enumscribe] }
Expand description
Derives enumscribe::ScribeCowStr
for an enum. This allows the enum to be converted to
a Cow<'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.
This derive also supports annotating a variant with #[enumscibe(other)]
, which is useful
because it is required to derive Unscribe
. This allows you to
specify that a variant should be used to store strings that could not be matched to any other
variant when unscribing. The variant should have a single field, which should have type
String
.
If you do not want to use #[enumscribe(other)]
, you should derive
ScribeStaticStr
instead.
This derive does not support ignoring variants with #[enumscribe(ignore)]
. If you want to
ignore variants, try deriving TryScribeCowStr
instead.