#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

#85 in No standard library

Download history 171/week @ 2024-07-27 218/week @ 2024-08-03 54/week @ 2024-08-10 75/week @ 2024-08-17 99/week @ 2024-08-24 80/week @ 2024-08-31 240/week @ 2024-09-07 77/week @ 2024-09-14 360/week @ 2024-09-21 109/week @ 2024-09-28 67/week @ 2024-10-05 71/week @ 2024-10-12 261/week @ 2024-10-19 202/week @ 2024-10-26 248/week @ 2024-11-02 149/week @ 2024-11-09

871 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