diff options
Diffstat (limited to 'vendor/bitflags/src/public.rs')
-rw-r--r-- | vendor/bitflags/src/public.rs | 170 |
1 files changed, 106 insertions, 64 deletions
diff --git a/vendor/bitflags/src/public.rs b/vendor/bitflags/src/public.rs index eb8e4c5d5..967e0dacb 100644 --- a/vendor/bitflags/src/public.rs +++ b/vendor/bitflags/src/public.rs @@ -130,8 +130,8 @@ macro_rules! __impl_public_bitflags { ( $BitFlags:ident: $T:ty, $PublicBitFlags:ident { $( - $(#[$attr:ident $($args:tt)*])* - $Flag:ident; + $(#[$inner:ident $($args:tt)*])* + const $Flag:tt = $value:expr; )* } ) => { @@ -142,7 +142,23 @@ macro_rules! __impl_public_bitflags { } fn all() { - Self::from_bits_truncate(<$T as $crate::Bits>::ALL) + let mut truncated = <$T as $crate::Bits>::EMPTY; + let mut i = 0; + + $( + __bitflags_expr_safe_attrs!( + $(#[$inner $($args)*])* + {{ + let flag = <$PublicBitFlags as $crate::Flags>::FLAGS[i].value().bits(); + + truncated = truncated | flag; + i += 1; + }} + ); + )* + + let _ = i; + Self::from_bits_retain(truncated) } fn bits(f) { @@ -160,24 +176,7 @@ macro_rules! __impl_public_bitflags { } fn from_bits_truncate(bits) { - if bits == <$T as $crate::Bits>::EMPTY { - return Self(bits) - } - - let mut truncated = <$T as $crate::Bits>::EMPTY; - - $( - __bitflags_expr_safe_attrs!( - $(#[$attr $($args)*])* - { - if bits & $PublicBitFlags::$Flag.bits() == $PublicBitFlags::$Flag.bits() { - truncated = truncated | $PublicBitFlags::$Flag.bits() - } - } - ); - )* - - Self(truncated) + Self(bits & Self::all().bits()) } fn from_bits_retain(bits) { @@ -186,14 +185,20 @@ macro_rules! __impl_public_bitflags { fn from_name(name) { $( - __bitflags_expr_safe_attrs!( - $(#[$attr $($args)*])* - { - if name == $crate::__private::core::stringify!($Flag) { - return $crate::__private::core::option::Option::Some(Self($PublicBitFlags::$Flag.bits())); - } - } - ); + __bitflags_flag!({ + name: $Flag, + named: { + __bitflags_expr_safe_attrs!( + $(#[$inner $($args)*])* + { + if name == $crate::__private::core::stringify!($Flag) { + return $crate::__private::core::option::Option::Some(Self($PublicBitFlags::$Flag.bits())); + } + } + ); + }, + unnamed: {}, + }); )* let _ = name; @@ -219,15 +224,15 @@ macro_rules! __impl_public_bitflags { } fn insert(f, other) { - *f = Self::from_bits_retain(f.bits() | other.bits()); + *f = Self::from_bits_retain(f.bits()).union(other); } fn remove(f, other) { - *f = Self::from_bits_retain(f.bits() & !other.bits()); + *f = Self::from_bits_retain(f.bits()).difference(other); } fn toggle(f, other) { - *f = Self::from_bits_retain(f.bits() ^ other.bits()); + *f = Self::from_bits_retain(f.bits()).symmetric_difference(other); } fn set(f, other, value) { @@ -268,7 +273,10 @@ macro_rules! __impl_public_bitflags { macro_rules! __impl_public_bitflags_iter { ($BitFlags:ident: $T:ty, $PublicBitFlags:ident) => { impl $BitFlags { - /// Iterate over enabled flag values. + /// Yield a set of contained flags values. + /// + /// Each yielded flags value will correspond to a defined named flag. Any unknown bits + /// will be yielded together as a final flags value. #[inline] pub const fn iter(&self) -> $crate::iter::Iter<$PublicBitFlags> { $crate::iter::Iter::__private_const_new( @@ -278,7 +286,10 @@ macro_rules! __impl_public_bitflags_iter { ) } - /// Iterate over enabled flag values with their stringified names. + /// Yield a set of contained named flags values. + /// + /// This method is like [`iter`](#method.iter), except only yields bits in contained named flags. + /// Any unknown bits, or bits not corresponding to a contained flag will not be yielded. #[inline] pub const fn iter_names(&self) -> $crate::iter::IterNames<$PublicBitFlags> { $crate::iter::IterNames::__private_const_new( @@ -344,7 +355,7 @@ macro_rules! __impl_public_bitflags_ops { impl $crate::__private::core::ops::BitOr for $PublicBitFlags { type Output = Self; - /// Returns the union of the two sets of flags. + /// The bitwise or (`|`) of the bits in two flags values. #[inline] fn bitor(self, other: $PublicBitFlags) -> Self { self.union(other) @@ -352,17 +363,17 @@ macro_rules! __impl_public_bitflags_ops { } impl $crate::__private::core::ops::BitOrAssign for $PublicBitFlags { - /// Adds the set of flags. + /// The bitwise or (`|`) of the bits in two flags values. #[inline] fn bitor_assign(&mut self, other: Self) { - *self = Self::from_bits_retain(self.bits()).union(other); + self.insert(other); } } impl $crate::__private::core::ops::BitXor for $PublicBitFlags { type Output = Self; - /// Returns the left flags, but with all the right flags toggled. + /// The bitwise exclusive-or (`^`) of the bits in two flags values. #[inline] fn bitxor(self, other: Self) -> Self { self.symmetric_difference(other) @@ -370,17 +381,17 @@ macro_rules! __impl_public_bitflags_ops { } impl $crate::__private::core::ops::BitXorAssign for $PublicBitFlags { - /// Toggles the set of flags. + /// The bitwise exclusive-or (`^`) of the bits in two flags values. #[inline] fn bitxor_assign(&mut self, other: Self) { - *self = Self::from_bits_retain(self.bits()).symmetric_difference(other); + self.toggle(other); } } impl $crate::__private::core::ops::BitAnd for $PublicBitFlags { type Output = Self; - /// Returns the intersection between the two sets of flags. + /// The bitwise and (`&`) of the bits in two flags values. #[inline] fn bitand(self, other: Self) -> Self { self.intersection(other) @@ -388,7 +399,7 @@ macro_rules! __impl_public_bitflags_ops { } impl $crate::__private::core::ops::BitAndAssign for $PublicBitFlags { - /// Disables all flags disabled in the set. + /// The bitwise and (`&`) of the bits in two flags values. #[inline] fn bitand_assign(&mut self, other: Self) { *self = Self::from_bits_retain(self.bits()).intersection(other); @@ -398,7 +409,10 @@ macro_rules! __impl_public_bitflags_ops { impl $crate::__private::core::ops::Sub for $PublicBitFlags { type Output = Self; - /// Returns the set difference of the two sets of flags. + /// The intersection of a source flags value with the complement of a target flags value (`&!`). + /// + /// This method is not equivalent to `self & !other` when `other` has unknown bits set. + /// `difference` won't truncate `other`, but the `!` operator will. #[inline] fn sub(self, other: Self) -> Self { self.difference(other) @@ -406,17 +420,20 @@ macro_rules! __impl_public_bitflags_ops { } impl $crate::__private::core::ops::SubAssign for $PublicBitFlags { - /// Disables all flags enabled in the set. + /// The intersection of a source flags value with the complement of a target flags value (`&!`). + /// + /// This method is not equivalent to `self & !other` when `other` has unknown bits set. + /// `difference` won't truncate `other`, but the `!` operator will. #[inline] fn sub_assign(&mut self, other: Self) { - *self = Self::from_bits_retain(self.bits()).difference(other); + self.remove(other); } } impl $crate::__private::core::ops::Not for $PublicBitFlags { type Output = Self; - /// Returns the complement of this set of flags. + /// The bitwise negation (`!`) of the bits in a flags value, truncating the result. #[inline] fn not(self) -> Self { self.complement() @@ -424,6 +441,7 @@ macro_rules! __impl_public_bitflags_ops { } impl $crate::__private::core::iter::Extend<$PublicBitFlags> for $PublicBitFlags { + /// The bitwise or (`|`) of the bits in each flags value. fn extend<T: $crate::__private::core::iter::IntoIterator<Item = Self>>( &mut self, iterator: T, @@ -435,6 +453,7 @@ macro_rules! __impl_public_bitflags_ops { } impl $crate::__private::core::iter::FromIterator<$PublicBitFlags> for $PublicBitFlags { + /// The bitwise or (`|`) of the bits in each flags value. fn from_iter<T: $crate::__private::core::iter::IntoIterator<Item = Self>>( iterator: T, ) -> Self { @@ -455,35 +474,58 @@ macro_rules! __impl_public_bitflags_consts { ( $PublicBitFlags:ident: $T:ty { $( - $(#[$attr:ident $($args:tt)*])* - $Flag:ident = $value:expr; + $(#[$inner:ident $($args:tt)*])* + const $Flag:tt = $value:expr; )* } ) => { impl $PublicBitFlags { $( - $(#[$attr $($args)*])* - #[allow( - deprecated, - non_upper_case_globals, - )] - pub const $Flag: Self = Self::from_bits_retain($value); + __bitflags_flag!({ + name: $Flag, + named: { + $(#[$inner $($args)*])* + #[allow( + deprecated, + non_upper_case_globals, + )] + pub const $Flag: Self = Self::from_bits_retain($value); + }, + unnamed: {}, + }); )* } impl $crate::Flags for $PublicBitFlags { const FLAGS: &'static [$crate::Flag<$PublicBitFlags>] = &[ $( - __bitflags_expr_safe_attrs!( - $(#[$attr $($args)*])* - { - #[allow( - deprecated, - non_upper_case_globals, - )] - $crate::Flag::new($crate::__private::core::stringify!($Flag), $PublicBitFlags::$Flag) - } - ), + __bitflags_flag!({ + name: $Flag, + named: { + __bitflags_expr_safe_attrs!( + $(#[$inner $($args)*])* + { + #[allow( + deprecated, + non_upper_case_globals, + )] + $crate::Flag::new($crate::__private::core::stringify!($Flag), $PublicBitFlags::$Flag) + } + ) + }, + unnamed: { + __bitflags_expr_safe_attrs!( + $(#[$inner $($args)*])* + { + #[allow( + deprecated, + non_upper_case_globals, + )] + $crate::Flag::new("", $PublicBitFlags::from_bits_retain($value)) + } + ) + }, + }), )* ]; |