Merge pull request #211 from niklasf/is-all-extra-bits

Let is_all() ignore extra bits (fixes #208)
This commit is contained in:
Ashley Mannix
2021-05-16 15:35:42 +10:00
committed by GitHub
+6 -1
View File
@@ -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
}
}
@@ -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());