enum-path
Derive FromStr and Display impls for enums that follow a hierarchical
path-like serialization scheme.
use enum_path::EnumPath;
#[derive(EnumPath)]
#[enum_path(FromStr, Display, rename_all = "snake_case")]
enum Action {
Exit,
SendMessage(String),
SetState(State),
}
#[derive(EnumPath)]
#[enum_path(FromStr, Display)]
enum State {
Idle,
Ready,
Running(Phase),
}
#[derive(EnumPath)]
#[enum_path(FromStr, Display)]
enum Phase {
Init,
Execute,
}
let action: Action = "set_state.Running.Execute".parse().unwrap();
assert_eq!(action.to_string(), "set_state.Running.Execute");
Enum-level attributes
| Attribute |
Effect |
FromStr |
Derive core::str::FromStr. |
Display |
Derive core::fmt::Display. |
rename_all = "..." |
Rename every variant; supports the usual serde-style cases. |
delimiter = "..." |
Separator between a variant name and its inner type (default "."). |
case_insensitive |
Parse variant names with eq_ignore_ascii_case. |
error = MyError |
Use a custom error type that implements From<enum_path::Error>. |
crate = path |
Override the runtime crate path when enum_path is re-exported. |
Per-variant attributes
| Attribute |
Effect |
rename = "..." |
Override this variant's serialized name. |