Expand description
#[derive(EnumStrings)]: a const fn per named string on a unit enum,
where every variant must supply every string or the derive fails.
use enum_strings::EnumStrings;
#[derive(Clone, Copy, EnumStrings)]
enum Route {
#[strings(path = "/", label = "Home")]
Home,
#[strings(path = "/docs", label = "Docs")]
Docs,
}
assert_eq!(Route::Docs.path(), "/docs");
assert_eq!(Route::Home.label(), "Home");The first variant decides which strings exist. A variant that leaves one
out, adds one, or repeats one is a compile error on that variant, which is
the check a match gives you and a runtime property lookup does not.
Derive Macrosยง
- Enum
Strings - See the crate documentation.