c-enum

Crates.ioc-enum
lib.rsc-enum
version0.2.3
sourcesrc
created_at2023-05-17 05:57:05.755677
updated_at2024-02-07 10:33:43.255188
descriptionA macro to generate c-like enums.
homepage
repositoryhttps://github.com/Phantomical/c-enum.git
max_upload_size
id866689
size102,759
Sean Lynch (Phantomical)

documentation

README

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"),
    }
}
Commit count: 35

cargo fmt