Skip to content

Commit f134f90

Browse files
committed
Generate push_next function for non root structs
Fixes #229
1 parent 8d7dfee commit f134f90

File tree

1 file changed

+33
-30
lines changed

1 file changed

+33
-30
lines changed

generator/src/lib.rs

+33-30
Original file line numberDiff line numberDiff line change
@@ -1749,46 +1749,49 @@ pub fn derive_setters(
17491749
.map(|extends| {
17501750
extends
17511751
.split(',')
1752-
.filter(|extend| root_struct_names.contains(*extend))
1752+
//.filter(|extend| root_struct_names.contains(*extend))
17531753
.map(|extends| name_to_tokens(&format!("Extends{}", name_to_tokens(&extends))))
17541754
.collect()
17551755
})
17561756
.unwrap_or_else(|| vec![]);
17571757

1758-
// We only implement a next methods for root structs with a `pnext` field.
1759-
let next_function = if has_next && root_structs.is_empty() {
1760-
quote! {
1761-
/// Prepends the given extension struct between the root and the first pointer. This
1762-
/// method only exists on structs that can be passed to a function directly. Only
1763-
/// valid extension structs can be pushed into the chain.
1764-
/// If the chain looks like `A -> B -> C`, and you call `builder.push_next(&mut D)`, then the
1765-
/// chain will look like `A -> D -> B -> C`.
1766-
pub fn push_next<T: #extends_name>(mut self, next: &'a mut T) -> #name_builder<'a> {
1767-
unsafe{
1768-
let next_ptr = next as *mut T as *mut BaseOutStructure;
1769-
// `next` here can contain a pointer chain. This means that we must correctly
1770-
// attach he head to the root and the tail to the rest of the chain
1771-
// For example:
1772-
//
1773-
// next = A -> B
1774-
// Before: `Root -> C -> D -> E`
1775-
// After: `Root -> A -> B -> C -> D -> E`
1776-
// ^^^^^^
1777-
// next chain
1778-
let last_next = ptr_chain_iter(next).last().unwrap();
1779-
(*last_next).p_next = self.inner.p_next as _;
1780-
self.inner.p_next = next_ptr as _;
1758+
// We only implement a push_next method for root structs with a `pnext` field.
1759+
let next_function =
1760+
if has_next && (root_structs.is_empty() || &_struct.name == "VkPhysicalDeviceFeatures2") {
1761+
quote! {
1762+
/// Prepends the given extension struct between the root and the first pointer. This
1763+
/// method only exists on structs that can be passed to a function directly. Only
1764+
/// valid extension structs can be pushed into the chain.
1765+
/// If the chain looks like `A -> B -> C`, and you call `builder.push_next(&mut D)`, then the
1766+
/// chain will look like `A -> D -> B -> C`.
1767+
pub fn push_next<T: #extends_name>(mut self, next: &'a mut T) -> #name_builder<'a> {
1768+
unsafe{
1769+
let next_ptr = next as *mut T as *mut BaseOutStructure;
1770+
// `next` here can contain a pointer chain. This means that we must correctly
1771+
// attach the head to the root and the tail to the rest of the chain
1772+
// For example:
1773+
//
1774+
// next = A -> B
1775+
// Before: `Root -> C -> D -> E`
1776+
// After: `Root -> A -> B -> C -> D -> E`
1777+
// ^^^^^^
1778+
// next chain
1779+
let last_next = ptr_chain_iter(next).last().unwrap();
1780+
(*last_next).p_next = self.inner.p_next as _;
1781+
self.inner.p_next = next_ptr as _;
1782+
}
1783+
self
17811784
}
1782-
self
17831785
}
1784-
}
1785-
} else {
1786-
quote! {}
1787-
};
1786+
} else {
1787+
quote! {}
1788+
};
17881789

17891790
// Root structs come with their own trait that structs that extends this struct will
17901791
// implement
1791-
let next_trait = if has_next && _struct.extends.is_none() {
1792+
let next_trait = if has_next
1793+
&& (_struct.extends.is_none() || &_struct.name == "VkPhysicalDeviceFeatures2")
1794+
{
17921795
quote! {
17931796
pub unsafe trait #extends_name {
17941797
}

0 commit comments

Comments
 (0)