This project is a set of custom derive attributes for bitflags that generates flags-aware implementations.
Add bitflags-derive to your Cargo.toml alongside bitflags:
[dependencies.bitflags-derive]
version = "0.0.5"
[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]externcrate bitflags;#[macro_use]externcrate bitflags_derive;bitflags!{
#[derive(FlagsDisplay,FlagsFromStr)]structMyFlags:u8{constA = 1;constB = 1 << 1;constC = 1 << 2;}}let flags = "A | B".parse::<MyFlags>()?;assert_eq!("A | B", flags.to_string());See the docs for details on all supported attributes.