https://github.com/seedyrom/enum-display
Macro for implementing std::fmt::Display on enum variants. Over 500K crates.io downloads!
https://github.com/seedyrom/enum-display
proc-macro proc-macro-derive rust
Last synced: 3 months ago
JSON representation
Macro for implementing std::fmt::Display on enum variants. Over 500K crates.io downloads!
- Host: GitHub
- URL: https://github.com/seedyrom/enum-display
- Owner: SeedyROM
- License: mit
- Created: 2022-09-28T03:32:15.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-02-09T08:47:07.000Z (about 2 years ago)
- Last Synced: 2025-01-29T02:18:11.347Z (about 1 year ago)
- Topics: proc-macro, proc-macro-derive, rust
- Language: Rust
- Homepage: https://docs.rs/enum-display
- Size: 25.4 KB
- Stars: 8
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# `enum-display`
[](https://github.com/SeedyROM/enum-display)
[](https://crates.io/crates/enum-display)
[](https://docs.rs/enum-display)
[](https://github.com/SeedyROM/enum-display/blob/main/LICENSE)
[](https://github.com/SeedyROM/enum-display/actions)
`enum-display` is a crate for implementing `std::fmt::Display` on enum variants with macros.
# Simple Example
```rust
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](https://docs.rs/convert_case/latest/convert_case/) is supported.
```rust
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");
```