Merge pull request #164 from Ralith/next-fix

Fix builder next methods
This commit is contained in:
Maik Klein 2018-12-01 09:17:12 +01:00 committed by GitHub
commit c1dc88e199
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 2715 additions and 2914 deletions

File diff suppressed because it is too large Load diff

View file

@ -1539,12 +1539,17 @@ pub fn derive_setters(_struct: &vkxml::Struct) -> Option<Tokens> {
}); });
let mut nexts = Vec::new(); let mut nexts = Vec::new();
let name_builder_next = name_to_tokens(&(_struct.name.clone() + "BuilderNext")); let extends_name = name_to_tokens(&format!("Extends{}", name));
if let Some(extends) = &_struct.extends { if let Some(extends) = &_struct.extends {
for target in extends.split(',') { for target in extends.split(',') {
let target_ident = name_to_tokens(&(target.to_string() + "BuilderNext")); let target = match target {
// https://github.com/KhronosGroup/Vulkan-Docs/pull/870
"VkPhysicalDeviceProperties" => "VkPhysicalDeviceProperties2",
x => x,
};
let target_ident = name_to_tokens(&format!("Extends{}", name_to_tokens(target)));
nexts.push(quote! { nexts.push(quote! {
unsafe impl #target_ident for #name_builder_next {} unsafe impl #target_ident for #name {}
}); });
} }
} }
@ -1552,14 +1557,14 @@ pub fn derive_setters(_struct: &vkxml::Struct) -> Option<Tokens> {
let next_function = if has_next { let next_function = if has_next {
if is_next_const { if is_next_const {
quote!{ quote!{
pub fn next<T>(mut self, next: &'a T) -> #name_builder<'a> where T: #name_builder_next { pub fn next<T>(mut self, next: &'a T) -> #name_builder<'a> where T: #extends_name {
self.inner.p_next = next as *const T as *const c_void; self.inner.p_next = next as *const T as *const c_void;
self self
} }
} }
} else { } else {
quote!{ quote!{
pub fn next<T>(mut self, next: &'a mut T) -> #name_builder<'a> where T: #name_builder_next { pub fn next<T>(mut self, next: &'a mut T) -> #name_builder<'a> where T: #extends_name {
self.inner.p_next = next as *mut T as *mut c_void; self.inner.p_next = next as *mut T as *mut c_void;
self self
} }
@ -1569,6 +1574,14 @@ pub fn derive_setters(_struct: &vkxml::Struct) -> Option<Tokens> {
quote!{} quote!{}
}; };
let next_trait = if has_next {
quote!{
pub unsafe trait #extends_name {}
}
} else {
quote!{}
};
let q = quote!{ let q = quote!{
impl #name { impl #name {
pub fn builder<'a>() -> #name_builder<'a> { pub fn builder<'a>() -> #name_builder<'a> {
@ -1584,7 +1597,7 @@ pub fn derive_setters(_struct: &vkxml::Struct) -> Option<Tokens> {
marker: ::std::marker::PhantomData<&'a ()>, marker: ::std::marker::PhantomData<&'a ()>,
} }
pub unsafe trait #name_builder_next {} #next_trait
#(#nexts)* #(#nexts)*