#[derive(Name)]
{
// Attributes available to this derive:
#[name]
}
Expand description
Generate a method name(&self) -> &'static str
that
returns the name of a given enum variant.
If the name-trait
feature is enabled, an implementation
of a Name
trait is generated. Otherwise, an inherent
implementation is used.
The name of an enum variant is its identifier in Title Case.
Foo
becomes "Foo"
and HelloWorld
becomes "Hello World"
.
This can be overridden by using the #[name = "..."]
attribute
on a variant, e.g.:
use enum_fun::Name;
#[derive(Name)]
enum Words {
Foo,
HelloWorld,
#[name = "Baz"]
Bar,
}
use Words::*;
assert_eq!(Foo.name(), "Foo");
assert_eq!(HelloWorld.name(), "Hello World");
assert_eq!(Bar.name(), "Baz");