#enums #display #traits #derive

macro enum-display-derive

Display trait's custom derive for simple enums

2 releases

Uses old Rust 2015

0.1.1 Feb 27, 2021
0.1.0 Feb 13, 2017

#669 in Procedural macros

Download history 8056/week @ 2024-11-18 7878/week @ 2024-11-25 9458/week @ 2024-12-02 9093/week @ 2024-12-09 7344/week @ 2024-12-16 4984/week @ 2024-12-23 5754/week @ 2024-12-30 8116/week @ 2025-01-06 9130/week @ 2025-01-13 9359/week @ 2025-01-20 8011/week @ 2025-01-27 8861/week @ 2025-02-03 9489/week @ 2025-02-10 9042/week @ 2025-02-17 10398/week @ 2025-02-24 10458/week @ 2025-03-03

40,162 downloads per month
Used in 70 crates (29 directly)

MIT/Apache

8KB
67 lines

Derive Display trait for enums

Build Status

Documentation

This crate can derive a Display implementation for very simple enums, like the following one:

#[macro_use]
extern crate enum_display_derive;

use std::fmt::Display;

#[derive(Display)]
enum FizzBuzz {
   Fizz,
   Buzz,
   FizzBuzz,
   Number(u64),
}

fn fb(i: u64) -> FizzBuzz {
   match (i % 3, i % 5) {
       (0, 0) => FizzBuzz::FizzBuzz,
       (0, _) => FizzBuzz::Fizz,
       (_, 0) => FizzBuzz::Buzz,
       (_, _) => FizzBuzz::Number(i),
   }
}

fn main() {
   for i in 0..100 {
       println!("{}", fb(i));
   }
}

You should see the following output:

FizzBuzz
1
2
Fizz
4
Buzz
Fizz
7
...

License

Licensed under either of

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.`

Dependencies

~1.5MB
~37K SLoC