mozilla/rust — pull request #13072 by bjz (2014-03-22 08:39:12+00:00)
Title: Add a bitset! macro

The `bitset!` macro generates a structure that holds a set of C-style bitmask flags. It is useful for creating typesafe wrappers for C APIs.

For example:

~~~rust
bitset!(Flags: u32 {
FlagA = 0x00000001,
FlagB = 0x00000010,
FlagC = 0x00000100,
FlagABC = FlagA.bits
| FlagB.bits
| FlagC.bits
})

let e1 = FlagA | FlagC;
let e2 = FlagB | FlagC;
assert_eq!(e1 | e2, FlagABC); // union
assert_eq!(e1 & e2, FlagC); // intersection
assert_eq!(e1 - e2, FlagA); // subtraction
~~~