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

Download history 101/week @ 2024-07-31 227/week @ 2024-08-07 16/week @ 2024-08-14 89/week @ 2024-08-21 125/week @ 2024-08-28 111/week @ 2024-09-04 185/week @ 2024-09-11 205/week @ 2024-09-18 235/week @ 2024-09-25 124/week @ 2024-10-02 58/week @ 2024-10-09 87/week @ 2024-10-16 248/week @ 2024-10-23 259/week @ 2024-10-30 222/week @ 2024-11-06 123/week @ 2024-11-13

876 downloads per month
Used in 4 crates (2 directly)

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