#partial-ord #enums #macro

no-std c-enum

A macro to generate c-like enums

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

#81 in No standard library

Download history 82/week @ 2024-07-14 9/week @ 2024-07-21 173/week @ 2024-07-28 218/week @ 2024-08-04 53/week @ 2024-08-11 74/week @ 2024-08-18 108/week @ 2024-08-25 72/week @ 2024-09-01 243/week @ 2024-09-08 75/week @ 2024-09-15 357/week @ 2024-09-22 111/week @ 2024-09-29 68/week @ 2024-10-06 72/week @ 2024-10-13 262/week @ 2024-10-20 207/week @ 2024-10-27

611 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