Skip to content

Instantly share code, notes, and snippets.

@grovesNL
Last active January 19, 2019 19:10
Show Gist options
  • Save grovesNL/5d3ddc7b95c1939be26c64ba09f1ac2f to your computer and use it in GitHub Desktop.
Save grovesNL/5d3ddc7b95c1939be26c64ba09f1ac2f to your computer and use it in GitHub Desktop.
[package]
name = "macro-expansion-bug"
version = "0.1.0"
authors = ["Joshua Groves <josh@joshgroves.com>"]
edition = "2018"
[dependencies]
bitflags = "1"
cargo rustc --lib --manifest-path ./Cargo.toml -- -Z unstable-options --pretty=expanded > expanded-2018-xx-xx-xxxxxxxxx.rs
#![feature(prelude_import)]
#![no_std]
#[prelude_import]
use ::std::prelude::v1::*;
#[macro_use]
extern crate std;
#[macro_use]
extern crate bitflags;
use bitflags::bitflags;
#[structural_match]
#[rustc_copy_clone_marker]
pub struct FLAGS {
bits: u32,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::marker::Copy for FLAGS { }
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for FLAGS {
#[inline]
fn eq(&self, other: &FLAGS) -> bool {
match *other {
FLAGS { bits: ref __self_1_0 } =>
match *self {
FLAGS { bits: ref __self_0_0 } =>
(*__self_0_0) == (*__self_1_0),
},
}
}
#[inline]
fn ne(&self, other: &FLAGS) -> bool {
match *other {
FLAGS { bits: ref __self_1_0 } =>
match *self {
FLAGS { bits: ref __self_0_0 } =>
(*__self_0_0) != (*__self_1_0),
},
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Eq for FLAGS {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
{ let _: ::std::cmp::AssertParamIsEq<u32>; }
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for FLAGS {
#[inline]
fn clone(&self) -> FLAGS {
{ let _: ::std::clone::AssertParamIsClone<u32>; *self }
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialOrd for FLAGS {
#[inline]
fn partial_cmp(&self, other: &FLAGS)
-> ::std::option::Option<::std::cmp::Ordering> {
match *other {
FLAGS { bits: ref __self_1_0 } =>
match *self {
FLAGS { bits: ref __self_0_0 } =>
match ::std::cmp::PartialOrd::partial_cmp(&(*__self_0_0),
&(*__self_1_0)) {
::std::option::Option::Some(::std::cmp::Ordering::Equal)
=>
::std::option::Option::Some(::std::cmp::Ordering::Equal),
cmp => cmp,
},
},
}
}
#[inline]
fn lt(&self, other: &FLAGS) -> bool {
match *other {
FLAGS { bits: ref __self_1_0 } =>
match *self {
FLAGS { bits: ref __self_0_0 } =>
::std::option::Option::unwrap_or(::std::cmp::PartialOrd::partial_cmp(&(*__self_0_0),
&(*__self_1_0)),
::std::cmp::Ordering::Greater)
== ::std::cmp::Ordering::Less,
},
}
}
#[inline]
fn le(&self, other: &FLAGS) -> bool {
match *other {
FLAGS { bits: ref __self_1_0 } =>
match *self {
FLAGS { bits: ref __self_0_0 } =>
::std::option::Option::unwrap_or(::std::cmp::PartialOrd::partial_cmp(&(*__self_0_0),
&(*__self_1_0)),
::std::cmp::Ordering::Greater)
!= ::std::cmp::Ordering::Greater,
},
}
}
#[inline]
fn gt(&self, other: &FLAGS) -> bool {
match *other {
FLAGS { bits: ref __self_1_0 } =>
match *self {
FLAGS { bits: ref __self_0_0 } =>
::std::option::Option::unwrap_or(::std::cmp::PartialOrd::partial_cmp(&(*__self_0_0),
&(*__self_1_0)),
::std::cmp::Ordering::Less)
== ::std::cmp::Ordering::Greater,
},
}
}
#[inline]
fn ge(&self, other: &FLAGS) -> bool {
match *other {
FLAGS { bits: ref __self_1_0 } =>
match *self {
FLAGS { bits: ref __self_0_0 } =>
::std::option::Option::unwrap_or(::std::cmp::PartialOrd::partial_cmp(&(*__self_0_0),
&(*__self_1_0)),
::std::cmp::Ordering::Less)
!= ::std::cmp::Ordering::Less,
},
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Ord for FLAGS {
#[inline]
fn cmp(&self, other: &FLAGS) -> ::std::cmp::Ordering {
match *other {
FLAGS { bits: ref __self_1_0 } =>
match *self {
FLAGS { bits: ref __self_0_0 } =>
match ::std::cmp::Ord::cmp(&(*__self_0_0), &(*__self_1_0)) {
::std::cmp::Ordering::Equal =>
::std::cmp::Ordering::Equal,
cmp => cmp,
},
},
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::hash::Hash for FLAGS {
fn hash<__H: ::std::hash::Hasher>(&self, state: &mut __H) -> () {
match *self {
FLAGS { bits: ref __self_0_0 } => {
::std::hash::Hash::hash(&(*__self_0_0), state)
}
}
}
}
impl ::bitflags::_core::fmt::Debug for FLAGS {
fn fmt(&self, f: &mut ::bitflags::_core::fmt::Formatter)
-> ::bitflags::_core::fmt::Result {
#[allow(non_snake_case)]
trait __BitFlags {
#[inline]
fn X(&self) -> bool { false }
#[inline]
fn Y(&self) -> bool { false }
#[inline]
fn Z(&self) -> bool { false }
}
impl __BitFlags for FLAGS {
#[allow(deprecated)]
#[inline]
fn X(&self) -> bool {
if Self::X.bits == 0 && self.bits != 0 {
false
} else { self.bits & Self::X.bits == Self::X.bits }
}
#[allow(deprecated)]
#[inline]
fn Y(&self) -> bool {
if Self::Y.bits == 0 && self.bits != 0 {
false
} else { self.bits & Self::Y.bits == Self::Y.bits }
}
#[allow(deprecated)]
#[inline]
fn Z(&self) -> bool {
if Self::Z.bits == 0 && self.bits != 0 {
false
} else { self.bits & Self::Z.bits == Self::Z.bits }
}
}
let mut first = true;
if <FLAGS as __BitFlags>::X(self) {
if !first { f.write_str(" | ")?; }
first = false;
f.write_str("X")?;
}
if <FLAGS as __BitFlags>::Y(self) {
if !first { f.write_str(" | ")?; }
first = false;
f.write_str("Y")?;
}
if <FLAGS as __BitFlags>::Z(self) {
if !first { f.write_str(" | ")?; }
first = false;
f.write_str("Z")?;
}
if first { f.write_str("(empty)")?; }
Ok(())
}
}
impl ::bitflags::_core::fmt::Binary for FLAGS {
fn fmt(&self, f: &mut ::bitflags::_core::fmt::Formatter)
-> ::bitflags::_core::fmt::Result {
::bitflags::_core::fmt::Binary::fmt(&self.bits, f)
}
}
impl ::bitflags::_core::fmt::Octal for FLAGS {
fn fmt(&self, f: &mut ::bitflags::_core::fmt::Formatter)
-> ::bitflags::_core::fmt::Result {
::bitflags::_core::fmt::Octal::fmt(&self.bits, f)
}
}
impl ::bitflags::_core::fmt::LowerHex for FLAGS {
fn fmt(&self, f: &mut ::bitflags::_core::fmt::Formatter)
-> ::bitflags::_core::fmt::Result {
::bitflags::_core::fmt::LowerHex::fmt(&self.bits, f)
}
}
impl ::bitflags::_core::fmt::UpperHex for FLAGS {
fn fmt(&self, f: &mut ::bitflags::_core::fmt::Formatter)
-> ::bitflags::_core::fmt::Result {
::bitflags::_core::fmt::UpperHex::fmt(&self.bits, f)
}
}
#[allow(dead_code)]
impl FLAGS {
pub const
X:
FLAGS
=
FLAGS{bits: 1,};
pub const
Y:
FLAGS
=
FLAGS{bits: 2,};
pub const
Z:
FLAGS
=
FLAGS{bits: 4,};
/// Returns an empty set of flags.
#[inline]
pub fn empty() -> FLAGS { FLAGS{bits: 0,} }
/// Returns the set containing all flags.
#[inline]
pub fn all() -> FLAGS {
#[allow(non_snake_case)]
trait __BitFlags {
#[inline]
fn X() -> u32 { 0 }
#[inline]
fn Y() -> u32 { 0 }
#[inline]
fn Z() -> u32 { 0 }
}
impl __BitFlags for FLAGS {
#[allow(deprecated)]
#[inline]
fn X() -> u32 { Self::X.bits }
#[allow(deprecated)]
#[inline]
fn Y() -> u32 { Self::Y.bits }
#[allow(deprecated)]
#[inline]
fn Z() -> u32 { Self::Z.bits }
}
FLAGS{bits:
<FLAGS as __BitFlags>::X() | <FLAGS as __BitFlags>::Y() |
<FLAGS as __BitFlags>::Z(),}
}
/// Returns the raw value of the flags currently stored.
#[inline]
pub fn bits(&self) -> u32 { self.bits }
/// Convert from underlying bit representation, unless that
/// representation contains bits that do not correspond to a flag.
#[inline]
pub fn from_bits(bits: u32) -> ::bitflags::_core::option::Option<FLAGS> {
if (bits & !FLAGS::all().bits()) == 0 {
::bitflags::_core::option::Option::Some(FLAGS{bits,})
} else { ::bitflags::_core::option::Option::None }
}
/// Convert from underlying bit representation, dropping any bits
/// that do not correspond to flags.
#[inline]
pub fn from_bits_truncate(bits: u32) -> FLAGS {
FLAGS{bits,} & FLAGS::all()
}
/// Returns `true` if no flags are currently stored.
#[inline]
pub fn is_empty(&self) -> bool { *self == FLAGS::empty() }
/// Returns `true` if all flags are currently set.
#[inline]
pub fn is_all(&self) -> bool { *self == FLAGS::all() }
/// Returns `true` if there are flags common to both `self` and `other`.
#[inline]
pub fn intersects(&self, other: FLAGS) -> bool {
!(*self & other).is_empty()
}
/// Returns `true` all of the flags in `other` are contained within `self`.
#[inline]
pub fn contains(&self, other: FLAGS) -> bool { (*self & other) == other }
/// Inserts the specified flags in-place.
#[inline]
pub fn insert(&mut self, other: FLAGS) { self.bits |= other.bits; }
/// Removes the specified flags in-place.
#[inline]
pub fn remove(&mut self, other: FLAGS) { self.bits &= !other.bits; }
/// Toggles the specified flags in-place.
#[inline]
pub fn toggle(&mut self, other: FLAGS) { self.bits ^= other.bits; }
/// Inserts or removes the specified flags depending on the passed value.
#[inline]
pub fn set(&mut self, other: FLAGS, value: bool) {
if value { self.insert(other); } else { self.remove(other); }
}
}
impl ::bitflags::_core::ops::BitOr for FLAGS {
type
Output
=
FLAGS;
/// Returns the union of the two sets of flags.
#[inline]
fn bitor(self, other: FLAGS) -> FLAGS {
FLAGS{bits: self.bits | other.bits,}
}
}
impl ::bitflags::_core::ops::BitOrAssign for FLAGS {
/// Adds the set of flags.
#[inline]
fn bitor_assign(&mut self, other: FLAGS) { self.bits |= other.bits; }
}
impl ::bitflags::_core::ops::BitXor for FLAGS {
type
Output
=
FLAGS;
/// Returns the left flags, but with all the right flags toggled.
#[inline]
fn bitxor(self, other: FLAGS) -> FLAGS {
FLAGS{bits: self.bits ^ other.bits,}
}
}
impl ::bitflags::_core::ops::BitXorAssign for FLAGS {
/// Toggles the set of flags.
#[inline]
fn bitxor_assign(&mut self, other: FLAGS) { self.bits ^= other.bits; }
}
impl ::bitflags::_core::ops::BitAnd for FLAGS {
type
Output
=
FLAGS;
/// Returns the intersection between the two sets of flags.
#[inline]
fn bitand(self, other: FLAGS) -> FLAGS {
FLAGS{bits: self.bits & other.bits,}
}
}
impl ::bitflags::_core::ops::BitAndAssign for FLAGS {
/// Disables all flags disabled in the set.
#[inline]
fn bitand_assign(&mut self, other: FLAGS) { self.bits &= other.bits; }
}
impl ::bitflags::_core::ops::Sub for FLAGS {
type
Output
=
FLAGS;
/// Returns the set difference of the two sets of flags.
#[inline]
fn sub(self, other: FLAGS) -> FLAGS {
FLAGS{bits: self.bits & !other.bits,}
}
}
impl ::bitflags::_core::ops::SubAssign for FLAGS {
/// Disables all flags enabled in the set.
#[inline]
fn sub_assign(&mut self, other: FLAGS) { self.bits &= !other.bits; }
}
impl ::bitflags::_core::ops::Not for FLAGS {
type
Output
=
FLAGS;
/// Returns the complement of this set of flags.
#[inline]
fn not(self) -> FLAGS { FLAGS{bits: !self.bits,} & FLAGS::all() }
}
impl ::bitflags::_core::iter::Extend<FLAGS> for FLAGS {
fn extend<T: ::bitflags::_core::iter::IntoIterator<Item =
FLAGS>>(&mut self, iterator: T) {
for item in iterator { self.insert(item) }
}
}
impl ::bitflags::_core::iter::FromIterator<FLAGS> for FLAGS {
fn from_iter<T: ::bitflags::_core::iter::IntoIterator<Item =
FLAGS>>(iterator: T) -> FLAGS {
let mut result = Self::empty();
result.extend(iterator);
result
}
}
#![feature(prelude_import)]
#![no_std]
#[prelude_import]
use ::std::prelude::v1::*;
#[macro_use]
extern crate std;
#[macro_use]
extern crate bitflags;
use bitflags::bitflags;
#[structural_match]
#[rustc_copy_clone_marker]
pub struct FLAGS {
bits: u32,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl $crate::marker::Copy for FLAGS { }
#[automatically_derived]
#[allow(unused_qualifications)]
impl $crate::cmp::PartialEq for FLAGS {
#[inline]
fn eq(&self, other: &FLAGS) -> bool {
match *other {
FLAGS { bits: ref __self_1_0 } =>
match *self {
FLAGS { bits: ref __self_0_0 } =>
(*__self_0_0) == (*__self_1_0),
},
}
}
#[inline]
fn ne(&self, other: &FLAGS) -> bool {
match *other {
FLAGS { bits: ref __self_1_0 } =>
match *self {
FLAGS { bits: ref __self_0_0 } =>
(*__self_0_0) != (*__self_1_0),
},
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl $crate::cmp::Eq for FLAGS {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
{ let _: $crate::cmp::AssertParamIsEq<u32>; }
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl $crate::clone::Clone for FLAGS {
#[inline]
fn clone(&self) -> FLAGS {
{ let _: $crate::clone::AssertParamIsClone<u32>; *self }
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl $crate::cmp::PartialOrd for FLAGS {
#[inline]
fn partial_cmp(&self, other: &FLAGS)
-> $crate::option::Option<$crate::cmp::Ordering> {
match *other {
FLAGS { bits: ref __self_1_0 } =>
match *self {
FLAGS { bits: ref __self_0_0 } =>
match $crate::cmp::PartialOrd::partial_cmp(&(*__self_0_0),
&(*__self_1_0)) {
$crate::option::Option::Some($crate::cmp::Ordering::Equal)
=>
$crate::option::Option::Some($crate::cmp::Ordering::Equal),
cmp => cmp,
},
},
}
}
#[inline]
fn lt(&self, other: &FLAGS) -> bool {
match *other {
FLAGS { bits: ref __self_1_0 } =>
match *self {
FLAGS { bits: ref __self_0_0 } =>
$crate::option::Option::unwrap_or($crate::cmp::PartialOrd::partial_cmp(&(*__self_0_0),
&(*__self_1_0)),
$crate::cmp::Ordering::Greater)
== $crate::cmp::Ordering::Less,
},
}
}
#[inline]
fn le(&self, other: &FLAGS) -> bool {
match *other {
FLAGS { bits: ref __self_1_0 } =>
match *self {
FLAGS { bits: ref __self_0_0 } =>
$crate::option::Option::unwrap_or($crate::cmp::PartialOrd::partial_cmp(&(*__self_0_0),
&(*__self_1_0)),
$crate::cmp::Ordering::Greater)
!= $crate::cmp::Ordering::Greater,
},
}
}
#[inline]
fn gt(&self, other: &FLAGS) -> bool {
match *other {
FLAGS { bits: ref __self_1_0 } =>
match *self {
FLAGS { bits: ref __self_0_0 } =>
$crate::option::Option::unwrap_or($crate::cmp::PartialOrd::partial_cmp(&(*__self_0_0),
&(*__self_1_0)),
$crate::cmp::Ordering::Less)
== $crate::cmp::Ordering::Greater,
},
}
}
#[inline]
fn ge(&self, other: &FLAGS) -> bool {
match *other {
FLAGS { bits: ref __self_1_0 } =>
match *self {
FLAGS { bits: ref __self_0_0 } =>
$crate::option::Option::unwrap_or($crate::cmp::PartialOrd::partial_cmp(&(*__self_0_0),
&(*__self_1_0)),
$crate::cmp::Ordering::Less)
!= $crate::cmp::Ordering::Less,
},
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl $crate::cmp::Ord for FLAGS {
#[inline]
fn cmp(&self, other: &FLAGS) -> $crate::cmp::Ordering {
match *other {
FLAGS { bits: ref __self_1_0 } =>
match *self {
FLAGS { bits: ref __self_0_0 } =>
match $crate::cmp::Ord::cmp(&(*__self_0_0), &(*__self_1_0)) {
$crate::cmp::Ordering::Equal =>
$crate::cmp::Ordering::Equal,
cmp => cmp,
},
},
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl $crate::hash::Hash for FLAGS {
fn hash<__H: $crate::hash::Hasher>(&self, state: &mut __H) -> () {
match *self {
FLAGS { bits: ref __self_0_0 } => {
$crate::hash::Hash::hash(&(*__self_0_0), state)
}
}
}
}
impl $crate::_core::fmt::Debug for FLAGS {
fn fmt(&self, f: &mut $crate::_core::fmt::Formatter)
-> $crate::_core::fmt::Result {
#[allow(non_snake_case)]
trait __BitFlags {
#[inline]
fn X(&self) -> bool { false }
#[inline]
fn Y(&self) -> bool { false }
#[inline]
fn Z(&self) -> bool { false }
}
impl __BitFlags for FLAGS {
#[allow(deprecated)]
#[inline]
fn X(&self) -> bool {
if Self::X.bits == 0 && self.bits != 0 {
false
} else { self.bits & Self::X.bits == Self::X.bits }
}
#[allow(deprecated)]
#[inline]
fn Y(&self) -> bool {
if Self::Y.bits == 0 && self.bits != 0 {
false
} else { self.bits & Self::Y.bits == Self::Y.bits }
}
#[allow(deprecated)]
#[inline]
fn Z(&self) -> bool {
if Self::Z.bits == 0 && self.bits != 0 {
false
} else { self.bits & Self::Z.bits == Self::Z.bits }
}
}
let mut first = true;
if <FLAGS as __BitFlags>::X(self) {
if !first { f.write_str(" | ")?; }
first = false;
f.write_str("X")?;
}
if <FLAGS as __BitFlags>::Y(self) {
if !first { f.write_str(" | ")?; }
first = false;
f.write_str("Y")?;
}
if <FLAGS as __BitFlags>::Z(self) {
if !first { f.write_str(" | ")?; }
first = false;
f.write_str("Z")?;
}
if first { f.write_str("(empty)")?; }
Ok(())
}
}
impl $crate::_core::fmt::Binary for FLAGS {
fn fmt(&self, f: &mut $crate::_core::fmt::Formatter)
-> $crate::_core::fmt::Result {
$crate::_core::fmt::Binary::fmt(&self.bits, f)
}
}
impl $crate::_core::fmt::Octal for FLAGS {
fn fmt(&self, f: &mut $crate::_core::fmt::Formatter)
-> $crate::_core::fmt::Result {
$crate::_core::fmt::Octal::fmt(&self.bits, f)
}
}
impl $crate::_core::fmt::LowerHex for FLAGS {
fn fmt(&self, f: &mut $crate::_core::fmt::Formatter)
-> $crate::_core::fmt::Result {
$crate::_core::fmt::LowerHex::fmt(&self.bits, f)
}
}
impl $crate::_core::fmt::UpperHex for FLAGS {
fn fmt(&self, f: &mut $crate::_core::fmt::Formatter)
-> $crate::_core::fmt::Result {
$crate::_core::fmt::UpperHex::fmt(&self.bits, f)
}
}
#[allow(dead_code)]
impl FLAGS {
pub const
X:
FLAGS
=
FLAGS{bits: 1,};
pub const
Y:
FLAGS
=
FLAGS{bits: 2,};
pub const
Z:
FLAGS
=
FLAGS{bits: 4,};
/// Returns an empty set of flags.
#[inline]
pub fn empty() -> FLAGS { FLAGS{bits: 0,} }
/// Returns the set containing all flags.
#[inline]
pub fn all() -> FLAGS {
#[allow(non_snake_case)]
trait __BitFlags {
#[inline]
fn X() -> u32 { 0 }
#[inline]
fn Y() -> u32 { 0 }
#[inline]
fn Z() -> u32 { 0 }
}
impl __BitFlags for FLAGS {
#[allow(deprecated)]
#[inline]
fn X() -> u32 { Self::X.bits }
#[allow(deprecated)]
#[inline]
fn Y() -> u32 { Self::Y.bits }
#[allow(deprecated)]
#[inline]
fn Z() -> u32 { Self::Z.bits }
}
FLAGS{bits:
<FLAGS as __BitFlags>::X() | <FLAGS as __BitFlags>::Y() |
<FLAGS as __BitFlags>::Z(),}
}
/// Returns the raw value of the flags currently stored.
#[inline]
pub fn bits(&self) -> u32 { self.bits }
/// Convert from underlying bit representation, unless that
/// representation contains bits that do not correspond to a flag.
#[inline]
pub fn from_bits(bits: u32) -> $crate::_core::option::Option<FLAGS> {
if (bits & !FLAGS::all().bits()) == 0 {
$crate::_core::option::Option::Some(FLAGS{bits,})
} else { $crate::_core::option::Option::None }
}
/// Convert from underlying bit representation, dropping any bits
/// that do not correspond to flags.
#[inline]
pub fn from_bits_truncate(bits: u32) -> FLAGS {
FLAGS{bits,} & FLAGS::all()
}
/// Returns `true` if no flags are currently stored.
#[inline]
pub fn is_empty(&self) -> bool { *self == FLAGS::empty() }
/// Returns `true` if all flags are currently set.
#[inline]
pub fn is_all(&self) -> bool { *self == FLAGS::all() }
/// Returns `true` if there are flags common to both `self` and `other`.
#[inline]
pub fn intersects(&self, other: FLAGS) -> bool {
!(*self & other).is_empty()
}
/// Returns `true` all of the flags in `other` are contained within `self`.
#[inline]
pub fn contains(&self, other: FLAGS) -> bool { (*self & other) == other }
/// Inserts the specified flags in-place.
#[inline]
pub fn insert(&mut self, other: FLAGS) { self.bits |= other.bits; }
/// Removes the specified flags in-place.
#[inline]
pub fn remove(&mut self, other: FLAGS) { self.bits &= !other.bits; }
/// Toggles the specified flags in-place.
#[inline]
pub fn toggle(&mut self, other: FLAGS) { self.bits ^= other.bits; }
/// Inserts or removes the specified flags depending on the passed value.
#[inline]
pub fn set(&mut self, other: FLAGS, value: bool) {
if value { self.insert(other); } else { self.remove(other); }
}
}
impl $crate::_core::ops::BitOr for FLAGS {
type
Output
=
FLAGS;
/// Returns the union of the two sets of flags.
#[inline]
fn bitor(self, other: FLAGS) -> FLAGS {
FLAGS{bits: self.bits | other.bits,}
}
}
impl $crate::_core::ops::BitOrAssign for FLAGS {
/// Adds the set of flags.
#[inline]
fn bitor_assign(&mut self, other: FLAGS) { self.bits |= other.bits; }
}
impl $crate::_core::ops::BitXor for FLAGS {
type
Output
=
FLAGS;
/// Returns the left flags, but with all the right flags toggled.
#[inline]
fn bitxor(self, other: FLAGS) -> FLAGS {
FLAGS{bits: self.bits ^ other.bits,}
}
}
impl $crate::_core::ops::BitXorAssign for FLAGS {
/// Toggles the set of flags.
#[inline]
fn bitxor_assign(&mut self, other: FLAGS) { self.bits ^= other.bits; }
}
impl $crate::_core::ops::BitAnd for FLAGS {
type
Output
=
FLAGS;
/// Returns the intersection between the two sets of flags.
#[inline]
fn bitand(self, other: FLAGS) -> FLAGS {
FLAGS{bits: self.bits & other.bits,}
}
}
impl $crate::_core::ops::BitAndAssign for FLAGS {
/// Disables all flags disabled in the set.
#[inline]
fn bitand_assign(&mut self, other: FLAGS) { self.bits &= other.bits; }
}
impl $crate::_core::ops::Sub for FLAGS {
type
Output
=
FLAGS;
/// Returns the set difference of the two sets of flags.
#[inline]
fn sub(self, other: FLAGS) -> FLAGS {
FLAGS{bits: self.bits & !other.bits,}
}
}
impl $crate::_core::ops::SubAssign for FLAGS {
/// Disables all flags enabled in the set.
#[inline]
fn sub_assign(&mut self, other: FLAGS) { self.bits &= !other.bits; }
}
impl $crate::_core::ops::Not for FLAGS {
type
Output
=
FLAGS;
/// Returns the complement of this set of flags.
#[inline]
fn not(self) -> FLAGS { FLAGS{bits: !self.bits,} & FLAGS::all() }
}
impl $crate::_core::iter::Extend<FLAGS> for FLAGS {
fn extend<T: $crate::_core::iter::IntoIterator<Item =
FLAGS>>(&mut self, iterator: T) {
for item in iterator { self.insert(item) }
}
}
impl $crate::_core::iter::FromIterator<FLAGS> for FLAGS {
fn from_iter<T: $crate::_core::iter::IntoIterator<Item =
FLAGS>>(iterator: T) -> FLAGS {
let mut result = Self::empty();
result.extend(iterator);
result
}
}
use bitflags::bitflags;
bitflags! {
pub struct FLAGS: u32 {
const X = 1;
const Y = 2;
const Z = 4;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment