Skip to content

Commit

Permalink
generator: Replace Extends{Root} with StructExtends<Root> generic
Browse files Browse the repository at this point in the history
Instead of emitting a new `trait` for every `Root` struct that is being
implemented by one or more "child" structs (those that have `Root` in
their `structextends`), create one trait that takes the root struct as a
generic parameter, and implement that directly instead.

This not only saves on having to define the `trait` for every
`Root` struct but also paves the way towards providing default trait
implementations for any pair of root and child struct, such as the
`p_next` builder methods.
  • Loading branch information
MarijnS95 committed Dec 7, 2024
1 parent 92a0ee6 commit 8e98f8d
Show file tree
Hide file tree
Showing 5 changed files with 1,754 additions and 1,964 deletions.
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `get_pipeline_executable_statistics()`.
The expected length of this array can be queried with the respective `*_len()` variant of these functions.
- `push_next()` has been renamed to `extend()` and marked as `unsafe`. Users are encouraged to call `push()` for singular structs instead. (#909)
- All `Extends{Root}` traits have been replaced with a single `Extends<Root>` trait using generics. (#971)

### Removed

Expand Down
14 changes: 14 additions & 0 deletions ash/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,4 +214,18 @@ mod tests {
};
assert_eq!(chain, chain2);
}
#[test]
fn test_dynamic_add_to_ptr_chain() {
let mut variable_pointers = vk::PhysicalDeviceVariablePointerFeatures::default();
let variable_pointers: &mut dyn vk::Extends<vk::DeviceCreateInfo<'_>> =
&mut variable_pointers;
let chain = alloc::vec![<*mut _>::cast(variable_pointers)];
let mut device_create_info = vk::DeviceCreateInfo::default().push(variable_pointers);
let chain2: Vec<*mut vk::BaseOutStructure<'_>> = unsafe {
vk::ptr_chain_iter(&mut device_create_info)
.skip(1)
.collect()
};
assert_eq!(chain, chain2);
}
}
Loading

0 comments on commit 8e98f8d

Please sign in to comment.