Derive Macro enumscribe_derive::TryUnscribe[][src]

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

Derives enumscribe::TryUnscribe for an enum. This allows a &str to be converted to an Option of the enum using the try_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.

Unlike Unscribe, there is no requirement to have a variant annotated with #[enumscribe(other)], although you may use it if you want. If there is an other variant, then the other variant will be returned when a string could not be matched to any other variant. If there is no other variant, None will be returned when a string could not be matched to any other variant.