mirror of
https://gitee.com/openharmony/third_party_rust_bitflags
synced 2024-11-23 07:10:11 +00:00
parent
efab7f3088
commit
75f7192557
65
src/lib.rs
65
src/lib.rs
@ -246,6 +246,9 @@
|
||||
#![cfg_attr(not(test), no_std)]
|
||||
#![doc(html_root_url = "https://docs.rs/bitflags/1.2.1")]
|
||||
|
||||
#[doc(hidden)]
|
||||
pub extern crate core as _core;
|
||||
|
||||
/// The macro used to generate the flag structures.
|
||||
///
|
||||
/// See the [crate level docs](../bitflags/index.html) for complete documentation.
|
||||
@ -394,8 +397,8 @@ macro_rules! __impl_bitflags {
|
||||
)*
|
||||
}
|
||||
) => {
|
||||
impl core::fmt::Debug for $BitFlags {
|
||||
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
|
||||
impl $crate::_core::fmt::Debug for $BitFlags {
|
||||
fn fmt(&self, f: &mut $crate::_core::fmt::Formatter) -> $crate::_core::fmt::Result {
|
||||
// This convoluted approach is to handle #[cfg]-based flag
|
||||
// omission correctly. For example it needs to support:
|
||||
//
|
||||
@ -448,7 +451,7 @@ macro_rules! __impl_bitflags {
|
||||
}
|
||||
first = false;
|
||||
f.write_str("0x")?;
|
||||
core::fmt::LowerHex::fmt(&extra_bits, f)?;
|
||||
$crate::_core::fmt::LowerHex::fmt(&extra_bits, f)?;
|
||||
}
|
||||
if first {
|
||||
f.write_str("(empty)")?;
|
||||
@ -456,24 +459,24 @@ macro_rules! __impl_bitflags {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
impl core::fmt::Binary for $BitFlags {
|
||||
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
|
||||
core::fmt::Binary::fmt(&self.bits, f)
|
||||
impl $crate::_core::fmt::Binary for $BitFlags {
|
||||
fn fmt(&self, f: &mut $crate::_core::fmt::Formatter) -> $crate::_core::fmt::Result {
|
||||
$crate::_core::fmt::Binary::fmt(&self.bits, f)
|
||||
}
|
||||
}
|
||||
impl core::fmt::Octal for $BitFlags {
|
||||
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
|
||||
core::fmt::Octal::fmt(&self.bits, f)
|
||||
impl $crate::_core::fmt::Octal for $BitFlags {
|
||||
fn fmt(&self, f: &mut $crate::_core::fmt::Formatter) -> $crate::_core::fmt::Result {
|
||||
$crate::_core::fmt::Octal::fmt(&self.bits, f)
|
||||
}
|
||||
}
|
||||
impl core::fmt::LowerHex for $BitFlags {
|
||||
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
|
||||
core::fmt::LowerHex::fmt(&self.bits, f)
|
||||
impl $crate::_core::fmt::LowerHex for $BitFlags {
|
||||
fn fmt(&self, f: &mut $crate::_core::fmt::Formatter) -> $crate::_core::fmt::Result {
|
||||
$crate::_core::fmt::LowerHex::fmt(&self.bits, f)
|
||||
}
|
||||
}
|
||||
impl core::fmt::UpperHex for $BitFlags {
|
||||
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
|
||||
core::fmt::UpperHex::fmt(&self.bits, f)
|
||||
impl $crate::_core::fmt::UpperHex for $BitFlags {
|
||||
fn fmt(&self, f: &mut $crate::_core::fmt::Formatter) -> $crate::_core::fmt::Result {
|
||||
$crate::_core::fmt::UpperHex::fmt(&self.bits, f)
|
||||
}
|
||||
}
|
||||
|
||||
@ -512,11 +515,11 @@ macro_rules! __impl_bitflags {
|
||||
/// Convert from underlying bit representation, unless that
|
||||
/// representation contains bits that do not correspond to a flag.
|
||||
#[inline]
|
||||
pub const fn from_bits(bits: $T) -> core::option::Option<$BitFlags> {
|
||||
pub const fn from_bits(bits: $T) -> $crate::_core::option::Option<$BitFlags> {
|
||||
if (bits & !$BitFlags::all().bits()) == 0 {
|
||||
core::option::Option::Some($BitFlags { bits })
|
||||
$crate::_core::option::Option::Some($BitFlags { bits })
|
||||
} else {
|
||||
core::option::Option::None
|
||||
$crate::_core::option::Option::None
|
||||
}
|
||||
}
|
||||
|
||||
@ -596,7 +599,7 @@ macro_rules! __impl_bitflags {
|
||||
}
|
||||
}
|
||||
|
||||
impl core::ops::BitOr for $BitFlags {
|
||||
impl $crate::_core::ops::BitOr for $BitFlags {
|
||||
type Output = $BitFlags;
|
||||
|
||||
/// Returns the union of the two sets of flags.
|
||||
@ -606,7 +609,7 @@ macro_rules! __impl_bitflags {
|
||||
}
|
||||
}
|
||||
|
||||
impl core::ops::BitOrAssign for $BitFlags {
|
||||
impl $crate::_core::ops::BitOrAssign for $BitFlags {
|
||||
|
||||
/// Adds the set of flags.
|
||||
#[inline]
|
||||
@ -615,7 +618,7 @@ macro_rules! __impl_bitflags {
|
||||
}
|
||||
}
|
||||
|
||||
impl core::ops::BitXor for $BitFlags {
|
||||
impl $crate::_core::ops::BitXor for $BitFlags {
|
||||
type Output = $BitFlags;
|
||||
|
||||
/// Returns the left flags, but with all the right flags toggled.
|
||||
@ -625,7 +628,7 @@ macro_rules! __impl_bitflags {
|
||||
}
|
||||
}
|
||||
|
||||
impl core::ops::BitXorAssign for $BitFlags {
|
||||
impl $crate::_core::ops::BitXorAssign for $BitFlags {
|
||||
|
||||
/// Toggles the set of flags.
|
||||
#[inline]
|
||||
@ -634,7 +637,7 @@ macro_rules! __impl_bitflags {
|
||||
}
|
||||
}
|
||||
|
||||
impl core::ops::BitAnd for $BitFlags {
|
||||
impl $crate::_core::ops::BitAnd for $BitFlags {
|
||||
type Output = $BitFlags;
|
||||
|
||||
/// Returns the intersection between the two sets of flags.
|
||||
@ -644,7 +647,7 @@ macro_rules! __impl_bitflags {
|
||||
}
|
||||
}
|
||||
|
||||
impl core::ops::BitAndAssign for $BitFlags {
|
||||
impl $crate::_core::ops::BitAndAssign for $BitFlags {
|
||||
|
||||
/// Disables all flags disabled in the set.
|
||||
#[inline]
|
||||
@ -653,7 +656,7 @@ macro_rules! __impl_bitflags {
|
||||
}
|
||||
}
|
||||
|
||||
impl core::ops::Sub for $BitFlags {
|
||||
impl $crate::_core::ops::Sub for $BitFlags {
|
||||
type Output = $BitFlags;
|
||||
|
||||
/// Returns the set difference of the two sets of flags.
|
||||
@ -663,7 +666,7 @@ macro_rules! __impl_bitflags {
|
||||
}
|
||||
}
|
||||
|
||||
impl core::ops::SubAssign for $BitFlags {
|
||||
impl $crate::_core::ops::SubAssign for $BitFlags {
|
||||
|
||||
/// Disables all flags enabled in the set.
|
||||
#[inline]
|
||||
@ -672,7 +675,7 @@ macro_rules! __impl_bitflags {
|
||||
}
|
||||
}
|
||||
|
||||
impl core::ops::Not for $BitFlags {
|
||||
impl $crate::_core::ops::Not for $BitFlags {
|
||||
type Output = $BitFlags;
|
||||
|
||||
/// Returns the complement of this set of flags.
|
||||
@ -682,16 +685,16 @@ macro_rules! __impl_bitflags {
|
||||
}
|
||||
}
|
||||
|
||||
impl core::iter::Extend<$BitFlags> for $BitFlags {
|
||||
fn extend<T: core::iter::IntoIterator<Item=$BitFlags>>(&mut self, iterator: T) {
|
||||
impl $crate::_core::iter::Extend<$BitFlags> for $BitFlags {
|
||||
fn extend<T: $crate::_core::iter::IntoIterator<Item=$BitFlags>>(&mut self, iterator: T) {
|
||||
for item in iterator {
|
||||
self.insert(item)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl core::iter::FromIterator<$BitFlags> for $BitFlags {
|
||||
fn from_iter<T: core::iter::IntoIterator<Item=$BitFlags>>(iterator: T) -> $BitFlags {
|
||||
impl $crate::_core::iter::FromIterator<$BitFlags> for $BitFlags {
|
||||
fn from_iter<T: $crate::_core::iter::IntoIterator<Item=$BitFlags>>(iterator: T) -> $BitFlags {
|
||||
let mut result = Self::empty();
|
||||
result.extend(iterator);
|
||||
result
|
||||
|
@ -1,5 +1,5 @@
|
||||
mod example {
|
||||
use bitflags::bitflags
|
||||
use bitflags::bitflags;
|
||||
|
||||
bitflags! {
|
||||
pub struct Flags1: u32 {
|
||||
|
9
test_suite/tests/redefine_core.rs
Normal file
9
test_suite/tests/redefine_core.rs
Normal file
@ -0,0 +1,9 @@
|
||||
use bitflags::bitflags;
|
||||
|
||||
// ensure that no naming conflicts happen
|
||||
mod core {}
|
||||
mod _core {}
|
||||
|
||||
bitflags! {
|
||||
struct Test: u8 {}
|
||||
}
|
Loading…
Reference in New Issue
Block a user