#bitflags #bit #flags #bitmask #macro-derive

no-std bitflags-derive

bitflags-aware #[derive] macros

4 releases

0.0.4 Feb 26, 2025
0.0.3 Feb 5, 2025
0.0.2 Feb 5, 2025
0.0.1 Feb 5, 2025

#352 in No standard library

Download history 397/week @ 2025-02-05 34/week @ 2025-02-12 6/week @ 2025-02-19 158/week @ 2025-02-26

595 downloads per month

MIT/Apache

9KB
76 lines

bitflags-derive

ci

This project is a set of custom derive attributes for bitflags that generates flags-aware implementations.

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());

See the docs for details on all supported attributes.

Dependencies

~255–770KB
~18K SLoC