Derive Macro enumscribe::TryScribeCowStr

source ·
#[derive(TryScribeCowStr)]
{
    // Attributes available to this derive:
    #[enumscribe]
}
Expand description

Derives enumscribe::TryScribeCowStr for an enum. This allows the enum to be converted to a Option<Cow<'static, str>> using the try_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 is a version of ScribeCowStr intended to be used if you have one or more variants annotated with #[enumscribe(ignore)]. Calling try_scribe() on an ignored variant will always return None.

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 TryScribeStaticStr instead.