#enum #display #derive #macro

macro enum-display-macro

A macro to derive Display for enums

4 releases

Uses new Rust 2021

0.1.3 Sep 28, 2022
0.1.2 Sep 28, 2022
0.1.1 Sep 28, 2022
0.1.0 Sep 28, 2022

#587 in Procedural macros

Download history 47/week @ 2022-10-08 822/week @ 2022-10-15 1364/week @ 2022-10-22 1066/week @ 2022-10-29 1330/week @ 2022-11-05 841/week @ 2022-11-12 589/week @ 2022-11-19 1095/week @ 2022-11-26 780/week @ 2022-12-03 1206/week @ 2022-12-10 867/week @ 2022-12-17 537/week @ 2022-12-24 574/week @ 2022-12-31 657/week @ 2023-01-07 1085/week @ 2023-01-14 664/week @ 2023-01-21

3,081 downloads per month
Used in 2 crates (via enum-display)

MIT license

5KB
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");

Dependencies

~0.7–1.2MB
~24K SLoC