mirror of
https://github.com/openharmony/third_party_rust_bitflags.git
synced 2026-07-18 01:16:02 -04:00
Merge pull request #211 from niklasf/is-all-extra-bits
Let is_all() ignore extra bits (fixes #208)
This commit is contained in:
+6
-1
@@ -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());
|
||||
|
||||
Reference in New Issue
Block a user