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

#65 in No standard library

Download history 144/week @ 2024-01-22 15/week @ 2024-01-29 176/week @ 2024-02-05 27/week @ 2024-02-19 89/week @ 2024-02-26 275/week @ 2024-03-04 113/week @ 2024-03-11 614/week @ 2024-03-18 354/week @ 2024-03-25 134/week @ 2024-04-01 211/week @ 2024-04-08 249/week @ 2024-04-15 346/week @ 2024-04-22 340/week @ 2024-04-29 173/week @ 2024-05-06

1,111 downloads per month
Used in 2 crates

MIT/Apache

68KB
1.5K SLoC

c-enum

ci badge crates.io badge docs.rs badge

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"),
    }
}

No runtime deps