-
Notifications
You must be signed in to change notification settings - Fork 192
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] Implement extension chaining #183
Changes from 1 commit
681eec5
6d72bb5
c46a41e
4f7ca18
3de2ca9
c66ae6b
1e13b99
d6a6aa3
38fe16f
215511f
04dbf20
2ecc483
4c1c8aa
88b1ac0
d667e58
bf29ebb
c8c8f69
1744159
2d730cd
7d5d200
cbc96b2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1591,14 +1591,13 @@ pub fn derive_setters( | |
name_to_tokens(&format!("Extends{}", name_to_tokens(&extends))) | ||
}); | ||
|
||
|
||
// We only implement a next methods for root create infos | ||
let next_function = if has_next && next_extends.is_none() { | ||
quote! { | ||
/// Prepend | ||
pub fn push_next<T: #extends_name>(mut self, next: &'a mut T) -> #name_builder<'a> { | ||
pub fn push_next<T: #extends_name>(mut self, next: &mut T) -> #name_builder<'a> { | ||
unsafe{ | ||
let next_ptr: *mut BaseOutStructure = ::std::mem::transmute(next); | ||
let next_ptr = next.as_ptr_mut(); | ||
(*next_ptr).p_next = self.inner.p_next as _; | ||
self.inner.p_next = next_ptr as _; | ||
} | ||
|
@@ -1613,7 +1612,9 @@ pub fn derive_setters( | |
// implement | ||
let next_trait = if has_next && _struct.extends.is_none() { | ||
quote! { | ||
pub unsafe trait #extends_name {} | ||
pub unsafe trait #extends_name { | ||
unsafe fn as_ptr_mut(&mut self) -> *mut BaseOutStructure; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of generating more code here, we should mark all builders as There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That is a great idea, I completely forgot about |
||
} | ||
} | ||
} else { | ||
quote! {} | ||
|
@@ -1622,7 +1623,16 @@ pub fn derive_setters( | |
// If the struct extends something we need to implement the root create info trait. | ||
let impl_extend_trait = if let Some(next_extends) = next_extends { | ||
quote! { | ||
unsafe impl #next_extends for #name {} | ||
unsafe impl #next_extends for #name_builder<'_> { | ||
unsafe fn as_ptr_mut(&mut self) -> *mut BaseOutStructure{ | ||
::std::mem::transmute(&mut self.inner) | ||
} | ||
} | ||
unsafe impl #next_extends for #name { | ||
unsafe fn as_ptr_mut(&mut self) -> *mut BaseOutStructure{ | ||
::std::mem::transmute(self) | ||
} | ||
} | ||
} | ||
} else { | ||
quote! {} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we be implementing the extension trait of every struct that this struct extends, rather than just an arbitrary one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you mean by arbitrary one? Only root create infos will create a new trait, and only non root create infos that extend a root create info will implement this trait.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unless I'm missing something, this seems to be used for deciding when to implement the trait, not when to define it. A single extension struct (e.g.
VkPhysicalDeviceVariablePointerFeatures
) can extend multiple root structs, and must implement all of their extension traits.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yes that is what I wanted to implement. I just chose the first one.