]> git.lizzy.rs Git - rust.git/commitdiff
auto merge of #14009 : jcmoyer/rust/bitflags-complement, r=alexcrichton
authorbors <bors@rust-lang.org>
Wed, 14 May 2014 16:21:25 +0000 (09:21 -0700)
committerbors <bors@rust-lang.org>
Wed, 14 May 2014 16:21:25 +0000 (09:21 -0700)
I feel that this is a very vital, missing piece of functionality. This adds on to #13072.

Only bits used in the definition of the bitflag are considered for the universe set. This is a bit safer than simply inverting all of the bits in the wrapped value.

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

...

// `Not` implements set complement
assert!(!(FlagB | FlagC) == FlagA);
// `all` and `is_all` are the inverses of `empty` and `is_empty`
assert!(Flags::all() - FlagA == !FlagA);
assert!(FlagABC.is_all());
```

1  2 
src/libstd/bitflags.rs
src/libstd/io/mod.rs

Simple merge
Simple merge