Switch to manual_derives

This commit is contained in:
Maik Klein 2018-08-20 07:30:10 +02:00
parent 6a329084e8
commit 8521f01488
2 changed files with 15 additions and 25 deletions

View file

@ -4977,13 +4977,13 @@ pub struct Offset3D {
pub z: int32_t, pub z: int32_t,
} }
#[repr(C)] #[repr(C)]
#[derive(Copy, Clone, Default, Debug, Hash, PartialEq)] #[derive(Copy, Clone, Default, Debug)]
pub struct Extent2D { pub struct Extent2D {
pub width: uint32_t, pub width: uint32_t,
pub height: uint32_t, pub height: uint32_t,
} }
#[repr(C)] #[repr(C)]
#[derive(Copy, Clone, Default, Debug, Hash, PartialEq)] #[derive(Copy, Clone, Default, Debug, PartialEq, Eq, Hash)]
pub struct Extent3D { pub struct Extent3D {
pub width: uint32_t, pub width: uint32_t,
pub height: uint32_t, pub height: uint32_t,
@ -7402,7 +7402,7 @@ impl ::std::default::Default for FramebufferCreateInfo {
} }
} }
#[repr(C)] #[repr(C)]
#[derive(Copy, Clone, Default, Debug, Hash, PartialEq)] #[derive(Copy, Clone, Default, Debug)]
pub struct DrawIndirectCommand { pub struct DrawIndirectCommand {
pub vertex_count: uint32_t, pub vertex_count: uint32_t,
pub instance_count: uint32_t, pub instance_count: uint32_t,
@ -7419,7 +7419,7 @@ pub struct DrawIndexedIndirectCommand {
pub first_instance: uint32_t, pub first_instance: uint32_t,
} }
#[repr(C)] #[repr(C)]
#[derive(Copy, Clone, Default, Debug, Hash, PartialEq)] #[derive(Copy, Clone, Default, Debug)]
pub struct DispatchIndirectCommand { pub struct DispatchIndirectCommand {
pub x: uint32_t, pub x: uint32_t,
pub y: uint32_t, pub y: uint32_t,
@ -11467,7 +11467,7 @@ impl ::std::default::Default for DescriptorSetVariableDescriptorCountLayoutSuppo
} }
} }
#[repr(C)] #[repr(C)]
#[derive(Copy, Clone, Default, Debug, Hash, PartialEq)] #[derive(Copy, Clone, Default, Debug)]
pub struct VertexInputBindingDivisorDescriptionEXT { pub struct VertexInputBindingDivisorDescriptionEXT {
pub binding: uint32_t, pub binding: uint32_t,
pub divisor: uint32_t, pub divisor: uint32_t,

View file

@ -1236,24 +1236,14 @@ pub fn derive_debug(_struct: &vkxml::Struct, union_types: &HashSet<&str>) -> Opt
Some(q) Some(q)
} }
pub fn auto_derive_partial_eq_hash(_struct: &vkxml::Struct) -> Tokens { /// At the moment `Ash` doesn't properly derive all the necessary drives
// TODO: Properly detect which types can implement PartialEq and Hash. /// like Eq, Hash etc.
// At the moment we only implement it for structs that contain primitivet /// To Address some cases, you can add the name of the struct that you
// types. /// require and add the missing derives yourself.
let is_primitive = _struct pub fn manual_derives(_struct: &vkxml::Struct) -> Tokens {
.elements match _struct.name.as_str() {
.iter() "VkExtent3D" | "VKExtent2D" => quote!{PartialEq, Eq, Hash,},
.filter_map(|elem| match *elem { _ => quote!{},
vkxml::StructElement::Member(ref field) => Some(field),
_ => None,
}).all(|field| match field.basetype.as_str() {
"c_float" | "uint32_t" => true,
_ => false,
});
if is_primitive {
quote!(Hash, PartialEq,)
} else {
quote!{}
} }
} }
pub fn generate_struct(_struct: &vkxml::Struct, union_types: &HashSet<&str>) -> Tokens { pub fn generate_struct(_struct: &vkxml::Struct, union_types: &HashSet<&str>) -> Tokens {
@ -1271,7 +1261,7 @@ pub fn generate_struct(_struct: &vkxml::Struct, union_types: &HashSet<&str>) ->
let debug_tokens = derive_debug(_struct, union_types); let debug_tokens = derive_debug(_struct, union_types);
let default_tokens = derive_default(_struct); let default_tokens = derive_default(_struct);
let partial_eq_hash_str = auto_derive_partial_eq_hash(_struct); let manual_derive_tokens = manual_derives(_struct);
let dbg_str = if debug_tokens.is_none() { let dbg_str = if debug_tokens.is_none() {
quote!(Debug,) quote!(Debug,)
} else { } else {
@ -1284,7 +1274,7 @@ pub fn generate_struct(_struct: &vkxml::Struct, union_types: &HashSet<&str>) ->
}; };
quote!{ quote!{
#[repr(C)] #[repr(C)]
#[derive(Copy, Clone, #default_str #dbg_str #partial_eq_hash_str)] #[derive(Copy, Clone, #default_str #dbg_str #manual_derive_tokens)]
pub struct #name { pub struct #name {
#(#params,)* #(#params,)*
} }