Crates.io | c-enum |
lib.rs | c-enum |
version | 0.2.3 |
source | src |
created_at | 2023-05-17 05:57:05.755677 |
updated_at | 2024-02-07 10:33:43.255188 |
description | A macro to generate c-like enums. |
homepage | |
repository | https://github.com/Phantomical/c-enum.git |
max_upload_size | |
id | 866689 |
size | 102,759 |
A rust macro for easily defining structs that act like C enums.
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"),
}
}