Derive Macro enumscribe::Unscribe

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

Derives enumscribe::Unscribe for an enum. This allows a &str to be converted to the enum using the unscribe() associated function.

You may annotate variants with #[enumscribe(str = "foo")] to specify what string should convert to the variant (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.

You may annotate a variant with #[enumscribe(case_insensitive)] to use case-insensitive matching for that variant. For example, if a variant is annotated with #[enumscribe(str = "baa", case_insensitive)], then strings like "baa", "BAA", "bAa" etc. will all be matched to that variant.

In order to derive this trait, you must have exactly one variant annotated with #[enumscribe(other)]. This variant will be used to store any string that could not be matched to any of the other variants. The variant must have exactly one field, which should have type String. Both named (Variant { name: String }) and unnamed (Variant(String)) fields are allowed.

If you do not want to use #[enumscribe(other)], try deriving TryUnscribe instead.