Crate auto_enum

source ·
Expand description

Provides automatic enum implementations that are convenient for working with FFI

#[macro_use]
extern crate auto_enum;
extern crate checked_enum;
 
#[auto_enum(u32, checked)]
pub enum SweepDirection {
    CounterClockwise = 0,
    Clockwise = 1,
}
 
assert_eq!(SweepDirection::from_u32(0), Some(SweepDirection::CounterClockwise));
#[macro_use]
extern crate auto_enum;
 
#[enum_flags(u32)]
pub enum BitmapOptions {
    TARGET = 0x1,
    CANNOT_DRAW = 0x2,
    CPU_READ = 0x4,
    GDI_COMPATIBLE = 0x8,
}
 
let flags = BitmapOptions::TARGET | BitmapOptions::GDI_COMPATIBLE;
assert!(flags.is_set(BitmapOptions::TARGET));
assert!(!flags.is_set(BitmapOptions::CPU_READ));

Attribute Macros

Generates methods for converting an enum value to and from its integer representation safely. Defaults to u32 representation.
Generates a bitflag wrapper struct containing the specified representation type. Representation defaults to u32.