Bitflags handling and storage.
This crate allows you to define flag values using an enum and derive
BitFlags to add convenience methods.
This implementation was heavily inspired by enumflags2 and bitflags and customized for use in a sawp parser. Consider using those two open source projects before resorting to this one. One key feature is that we are automatically generating ffi accessors using the sawp-ffi crate.
This crate works as follows:
enum YourEnumwith a numeric representation (e.g.#[repr(u8)]) is used to define bit fields.- deriving
BitFlagson this enum will add convenience methods for bitwise operations and implement theFlagtrait. - Flag values are transparently stored as
Flags<YourEnum>so you can perform more operations on this type.
Example
See example module for a generated example as well.
use ;
/// Example enum
// `flags` will be of transparent type `Flags<Test>`
let flags : = A | C;
// convert a number to flags using `from_bits()`
assert_eq!;
// convert flags to a number using `bits()`
assert_eq!;
// perform bitwise operations
assert_eq!;
assert_eq!;
assert_eq!;
// check which flags are set
assert!;
assert!;
assert!;
assert!;