enum-path 0.1.0

Derive FromStr and Display impls for enums that follow a hierarchical path-like serialization scheme
Documentation
  • Coverage
  • 100%
    4 out of 4 items documented1 out of 2 items with examples
  • Size
  • Source code size: 43.44 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 207.03 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 10s Average build duration of successful builds.
  • all releases: 10s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Repository
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • DannyStoll1

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.