Skip to content

Commit

Permalink
Merge pull request #211 from niklasf/is-all-extra-bits
Browse files Browse the repository at this point in the history
Let is_all() ignore extra bits (fixes #208)
  • Loading branch information
KodrAus committed May 16, 2021
2 parents ec76dd2 + 6437943 commit ae4f46f
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/lib.rs
Expand Up @@ -713,7 +713,7 @@ macro_rules! __impl_bitflags {
/// Returns `true` if all flags are currently set.
#[inline]
pub const fn is_all(&self) -> bool {
self.bits == $BitFlags::all().bits
$BitFlags::all().bits | self.bits == self.bits
}
}

Expand Down Expand Up @@ -1123,6 +1123,11 @@ mod tests {
assert!(!Flags::A.is_all());
assert!(Flags::ABC.is_all());

let extra = unsafe { Flags::from_bits_unchecked(0b1000) };
assert!(!extra.is_all());
assert!(!(Flags::A | extra).is_all());
assert!((Flags::ABC | extra).is_all());

assert!(AnotherSetOfFlags::ANOTHER_FLAG.is_all());

assert!(EmptyFlags::all().is_all());
Expand Down

0 comments on commit ae4f46f

Please sign in to comment.