More traits for dispatchable handles

This commit is contained in:
Benjamin Saunders 2018-09-16 12:15:01 -07:00
parent f13e01d026
commit aa171d405a
2 changed files with 1625 additions and 1697 deletions

File diff suppressed because it is too large Load diff

View file

@ -90,7 +90,7 @@ pub fn define_handle_macro() -> Tokens {
macro_rules! define_handle{ macro_rules! define_handle{
($name: ident, $ty: ident) => { ($name: ident, $ty: ident) => {
#[repr(transparent)] #[repr(transparent)]
#[derive(Clone, Copy, Debug)] #[derive(Eq, PartialEq, Ord, PartialOrd, Clone, Copy, Hash)]
pub struct $name(*mut u8); pub struct $name(*mut u8);
impl Default for $name { impl Default for $name {
fn default() -> $name { fn default() -> $name {
@ -112,6 +112,18 @@ pub fn define_handle_macro() -> Tokens {
$name(::std::ptr::null_mut()) $name(::std::ptr::null_mut())
} }
} }
impl fmt::Pointer for $name {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fmt::Pointer::fmt(&self.0, f)
}
}
impl fmt::Debug for $name {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fmt::Debug::fmt(&self.0, f)
}
}
} }
} }
} }
@ -136,14 +148,15 @@ pub fn handle_nondispatchable_macro() -> Tokens {
$name(0) $name(0)
} }
} }
impl ::std::fmt::Pointer for $name {
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::result::Result<(), ::std::fmt::Error> { impl fmt::Pointer for $name {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "0x{:x}", self.0) write!(f, "0x{:x}", self.0)
} }
} }
impl ::std::fmt::Debug for $name { impl fmt::Debug for $name {
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::result::Result<(), ::std::fmt::Error> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "0x{:x}", self.0) write!(f, "0x{:x}", self.0)
} }
} }
@ -192,8 +205,8 @@ pub fn vk_bitflags_wrapped_macro() -> Tokens {
$name(0) $name(0)
} }
} }
impl ::std::fmt::Debug for $name { impl fmt::Debug for $name {
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::result::Result<(), ::std::fmt::Error> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}({:b})", stringify!($name), self.0) write!(f, "{}({:b})", stringify!($name), self.0)
} }
} }
@ -1268,8 +1281,8 @@ pub fn derive_debug(_struct: &vkxml::Struct, union_types: &HashSet<&str>) -> Opt
}); });
let name_str = name.as_ref(); let name_str = name.as_ref();
let q = quote!{ let q = quote!{
impl ::std::fmt::Debug for #name { impl fmt::Debug for #name {
fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> ::std::result::Result<(), ::std::fmt::Error> { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
fmt.debug_struct(#name_str) fmt.debug_struct(#name_str)
#(#debug_fields)* #(#debug_fields)*
.finish() .finish()