7 releases
0.2.3 | Feb 7, 2024 |
---|---|
0.2.2 | Oct 24, 2023 |
0.1.2 | Sep 26, 2023 |
0.1.1 | May 17, 2023 |
#85 in No standard library
876 downloads per month
Used in 4 crates
(2 directly)
68KB
1.5K
SLoC
c-enum
A rust macro for easily defining structs that act like C enums.
Example
use c_enum::c_enum;
c_enum! {
#[derive(Copy, Clone, PartialEq, Eq, Ord, PartialOrd, Hash)]
pub enum Variant: u32 {
A,
B,
C = 5,
}
}
fn main() {
let v1 = Variant::A;
let v2 = Variant::from(77);
match v1 {
Variant::A => println!("A"), // named values...
Variant::B => println!("B"),
Variant(77) => println!("77"), // values without named variants also work
_ => println!("other value"),
}
}