#macro-derive #enums #display #macro #derive

enum-display

A macro to derive Display for enums

5 releases

0.1.4 Feb 9, 2024
0.1.3 Sep 28, 2022
0.1.2 Sep 28, 2022
0.1.1 Sep 28, 2022
0.1.0 Sep 28, 2022

#285 in Rust patterns

Download history 2376/week @ 2024-08-22 3088/week @ 2024-08-29 2541/week @ 2024-09-05 2441/week @ 2024-09-12 2468/week @ 2024-09-19 3442/week @ 2024-09-26 2271/week @ 2024-10-03 2394/week @ 2024-10-10 2453/week @ 2024-10-17 2432/week @ 2024-10-24 3071/week @ 2024-10-31 2778/week @ 2024-11-07 2943/week @ 2024-11-14 3055/week @ 2024-11-21 2274/week @ 2024-11-28 2805/week @ 2024-12-05

11,491 downloads per month
Used in 16 crates (7 directly)

MIT license

6KB
83 lines

enum-display

enum-display is a crate for implementing std::fmt::Display on enum variants with macros.

Simple Example

use enum_display::EnumDisplay;

#[derive(EnumDisplay)]
enum Color {
  Red,
  Green,
  Blue,
}

assert_eq!(Color::Red.to_string(), "Red");
assert_eq!(Color::Green.to_string(), "Green");
assert_eq!(Color::Blue.to_string(), "Blue");

Example With Custom Case Transform

Any case from convert_case is supported.

use enum_display::EnumDisplay;

#[derive(EnumDisplay)]
#[enum_display(case = "Kebab")]
enum Message {
    HelloGreeting { name: String },
}

assert_eq!(Message::HelloGreeting { name: "Alice".to_string() }.to_string(), "hello-greeting");

lib.rs:

enum-display is a crate for implementing std::fmt::Display on enum variants with macros.

Simple Example

use enum_display::EnumDisplay;

#[derive(EnumDisplay)]
enum Color {
   Red,
   Green,
   Blue,
}

assert_eq!(Color::Red.to_string(), "Red");
assert_eq!(Color::Green.to_string(), "Green");
assert_eq!(Color::Blue.to_string(), "Blue");

Example With Custom Case Transform

Any case from convert_case is supported.

use enum_display::EnumDisplay;

#[derive(EnumDisplay)]
#[enum_display(case = "Kebab")]
enum Message {
    HelloGreeting { name: String },
}

assert_eq!(Message::HelloGreeting { name: "Alice".to_string() }.to_string(), "hello-greeting");

Dependencies

~2MB
~43K SLoC