1 #[macro_export] 2 macro_rules! vk_bitflags_wrapped { 3 ($ name : ident , $ all : expr , $ flag_type : ty) => { 4 impl Default for $name { 5 fn default() -> $name { 6 $name(0) 7 } 8 } 9 impl $name { 10 #[inline] 11 pub const fn empty() -> $name { 12 $name(0) 13 } 14 #[inline] 15 pub const fn all() -> $name { 16 $name($all) 17 } 18 #[inline] 19 pub const fn from_raw(x: $flag_type) -> Self { 20 $name(x) 21 } 22 #[inline] 23 pub const fn as_raw(self) -> $flag_type { 24 self.0 25 } 26 #[inline] 27 pub fn is_empty(self) -> bool { 28 self == $name::empty() 29 } 30 #[inline] 31 pub fn is_all(self) -> bool { 32 self & $name::all() == $name::all() 33 } 34 #[inline] 35 pub fn intersects(self, other: $name) -> bool { 36 self & other != $name::empty() 37 } 38 #[doc = r" Returns whether `other` is a subset of `self`"] 39 #[inline] 40 pub fn contains(self, other: $name) -> bool { 41 self & other == other 42 } 43 } 44 impl ::std::ops::BitOr for $name { 45 type Output = $name; 46 #[inline] 47 fn bitor(self, rhs: $name) -> $name { 48 $name(self.0 | rhs.0) 49 } 50 } 51 impl ::std::ops::BitOrAssign for $name { 52 #[inline] 53 fn bitor_assign(&mut self, rhs: $name) { 54 *self = *self | rhs 55 } 56 } 57 impl ::std::ops::BitAnd for $name { 58 type Output = $name; 59 #[inline] 60 fn bitand(self, rhs: $name) -> $name { 61 $name(self.0 & rhs.0) 62 } 63 } 64 impl ::std::ops::BitAndAssign for $name { 65 #[inline] 66 fn bitand_assign(&mut self, rhs: $name) { 67 *self = *self & rhs 68 } 69 } 70 impl ::std::ops::BitXor for $name { 71 type Output = $name; 72 #[inline] 73 fn bitxor(self, rhs: $name) -> $name { 74 $name(self.0 ^ rhs.0) 75 } 76 } 77 impl ::std::ops::BitXorAssign for $name { 78 #[inline] 79 fn bitxor_assign(&mut self, rhs: $name) { 80 *self = *self ^ rhs 81 } 82 } 83 impl ::std::ops::Sub for $name { 84 type Output = $name; 85 #[inline] 86 fn sub(self, rhs: $name) -> $name { 87 self & !rhs 88 } 89 } 90 impl ::std::ops::SubAssign for $name { 91 #[inline] 92 fn sub_assign(&mut self, rhs: $name) { 93 *self = *self - rhs 94 } 95 } 96 impl ::std::ops::Not for $name { 97 type Output = $name; 98 #[inline] 99 fn not(self) -> $name { 100 self ^ $name::all() 101 } 102 } 103 }; 104 } 105 #[macro_export] 106 macro_rules! handle_nondispatchable { 107 ($ name : ident , $ ty : ident) => { 108 handle_nondispatchable!($name, $ty, doc = ""); 109 }; 110 ($ name : ident , $ ty : ident , $ doc_link : meta) => { 111 #[repr(transparent)] 112 #[derive(Eq, PartialEq, Ord, PartialOrd, Clone, Copy, Hash, Default)] 113 #[$doc_link] 114 pub struct $name(u64); 115 impl Handle for $name { 116 const TYPE: ObjectType = ObjectType::$ty; 117 fn as_raw(self) -> u64 { 118 self.0 as u64 119 } 120 fn from_raw(x: u64) -> Self { 121 $name(x as _) 122 } 123 } 124 impl $name { 125 pub const fn null() -> $name { 126 $name(0) 127 } 128 } 129 impl fmt::Pointer for $name { 130 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 131 write!(f, "0x{:x}", self.0) 132 } 133 } 134 impl fmt::Debug for $name { 135 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 136 write!(f, "0x{:x}", self.0) 137 } 138 } 139 }; 140 } 141 #[macro_export] 142 macro_rules! define_handle { 143 ($ name : ident , $ ty : ident) => { 144 define_handle!($name, $ty, doc = ""); 145 }; 146 ($ name : ident , $ ty : ident , $ doc_link : meta) => { 147 #[repr(transparent)] 148 #[derive(Eq, PartialEq, Ord, PartialOrd, Clone, Copy, Hash)] 149 #[$doc_link] 150 pub struct $name(*mut u8); 151 impl Default for $name { 152 fn default() -> $name { 153 $name::null() 154 } 155 } 156 impl Handle for $name { 157 const TYPE: ObjectType = ObjectType::$ty; 158 fn as_raw(self) -> u64 { 159 self.0 as u64 160 } 161 fn from_raw(x: u64) -> Self { 162 $name(x as _) 163 } 164 } 165 unsafe impl Send for $name {} 166 unsafe impl Sync for $name {} 167 impl $name { 168 pub const fn null() -> Self { 169 $name(::std::ptr::null_mut()) 170 } 171 } 172 impl fmt::Pointer for $name { 173 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 174 fmt::Pointer::fmt(&self.0, f) 175 } 176 } 177 impl fmt::Debug for $name { 178 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 179 fmt::Debug::fmt(&self.0, f) 180 } 181 } 182 }; 183 } 184