Crates.io | enum-display |
lib.rs | enum-display |
version | 0.1.4 |
source | src |
created_at | 2022-09-28 04:15:41.094575 |
updated_at | 2024-02-09 08:15:49.763981 |
description | A macro to derive Display for enums |
homepage | https://github.com/SeedyROM/enum-display |
repository | https://github.com/SeedyROM/enum-display |
max_upload_size | |
id | 675412 |
size | 5,128 |
enum-display
enum-display
is a crate for implementing std::fmt::Display
on enum variants with macros.
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");
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");