#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

#279 in Rust patterns

Download history 3016/week @ 2024-08-14 2271/week @ 2024-08-21 3217/week @ 2024-08-28 2369/week @ 2024-09-04 2626/week @ 2024-09-11 2054/week @ 2024-09-18 3822/week @ 2024-09-25 2145/week @ 2024-10-02 2568/week @ 2024-10-09 2477/week @ 2024-10-16 2409/week @ 2024-10-23 2997/week @ 2024-10-30 2814/week @ 2024-11-06 2823/week @ 2024-11-13 3204/week @ 2024-11-20 1848/week @ 2024-11-27

11,030 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
~42K SLoC