Crate bitflags_derive

Crate bitflags_derive 

Source
Expand description

Custom derive attributes for types generated by bitflags.

§Usage

Add bitflags-derive to your Cargo.toml alongside bitflags:

[dependencies.bitflags-derive]
version = "0.0.4"

[dependencies.bitflags]
version = "2"

Inside the bitflags! macro, add a #[derive] attribute with any traits from bitflags-derive that you’d like to support:

#[macro_use]
extern crate bitflags;

#[macro_use]
extern crate bitflags_derive;

bitflags! {
    #[derive(FlagsDisplay, FlagsFromStr)]
    struct MyFlags: u8 {
        const A = 1;
        const B = 1 << 1;
        const C = 1 << 2;
    }
}

let flags = "A | B".parse::<MyFlags>()?;

assert_eq!("A | B", flags.to_string());

These derives work for any type that implements the Flags trait.

Derive Macros§

FlagsDebug
Derive Debug.
FlagsDisplay
Derive Display.
FlagsFromStr
Derive FromStr.