@@ -51,7 +51,7 @@ pub trait Handle: Sized {
5151
5252/// Iterates through the pointer chain. Includes the item that is passed into the function. Stops at
5353/// the last [`BaseOutStructure`] that has a null [`BaseOutStructure::p_next`] field.
54- pub ( crate ) unsafe fn ptr_chain_iter < ' a , T : AnyTaggedStructure < ' a > + ?Sized > (
54+ pub ( crate ) unsafe fn ptr_chain_iter < ' a , T : TaggedStructure < ' a > + ?Sized > (
5555 ptr : & mut T ,
5656) -> impl Iterator < Item = * mut BaseOutStructure < ' _ > > {
5757 let ptr = <* mut T >:: cast :: < BaseOutStructure < ' _ > > ( ptr) ;
@@ -69,7 +69,9 @@ pub(crate) unsafe fn ptr_chain_iter<'a, T: AnyTaggedStructure<'a> + ?Sized>(
6969/// Structures implementing this trait are layout-compatible with [`BaseInStructure`] and
7070/// [`BaseOutStructure`]. Such structures have an `s_type` field indicating its type, which must
7171/// always match the value of [`TaggedStructure::STRUCTURE_TYPE`].
72- pub unsafe trait AnyTaggedStructure < ' a > {
72+ pub unsafe trait TaggedStructure < ' a > {
73+ const STRUCTURE_TYPE : StructureType ;
74+
7375 /// Prepends the given extension struct between the root and the first pointer. This method is
7476 /// only available on structs that can be passed to a function directly. Only valid extension
7577 /// structs can be pushed into the chain.
@@ -79,13 +81,13 @@ pub unsafe trait AnyTaggedStructure<'a> {
7981 /// # Panics
8082 /// If `next` contains a pointer chain of its own, this function will panic. Call `unsafe`
8183 /// [`Self::extend()`] to insert this chain instead.
82- fn push < T : Extends < ' a , Self > + ?Sized > ( mut self , next : & ' a mut T ) -> Self
84+ fn push < T : Extends < Self > + TaggedStructure < ' a > + ?Sized > ( mut self , next : & ' a mut T ) -> Self
8385 where
8486 Self : Sized ,
8587 {
86- // SAFETY: All implementors of `AnyTaggedStructure ` are required to have the `BaseOutStructure` layout
88+ // SAFETY: All implementors of `TaggedStructure ` are required to have the `BaseOutStructure` layout
8789 let slf_base = unsafe { & mut * <* mut _ >:: cast :: < BaseOutStructure < ' _ > > ( & mut self ) } ;
88- // SAFETY: All implementors of `T: Extends<'a, >: AnyTaggedStructure ` are required to have the `BaseOutStructure` layout
90+ // SAFETY: All implementors of `TaggedStructure ` are required to have the `BaseOutStructure` layout
8991 let next_base = unsafe { & mut * <* mut T >:: cast :: < BaseOutStructure < ' _ > > ( next) } ;
9092 // `next` here can contain a pointer chain. This function refuses to insert the struct,
9193 // in favour of calling unsafe extend().
@@ -111,7 +113,10 @@ pub unsafe trait AnyTaggedStructure<'a> {
111113 ///
112114 /// The last struct in this chain (i.e. the one where `p_next` is `NULL`) must be writable
113115 /// memory, as its `p_next` field will be updated with the value of `self.p_next`.
114- unsafe fn extend < T : Extends < ' a , Self > + ?Sized > ( mut self , next : & ' a mut T ) -> Self
116+ unsafe fn extend < T : Extends < Self > + TaggedStructure < ' a > + ?Sized > (
117+ mut self ,
118+ next : & ' a mut T ,
119+ ) -> Self
115120 where
116121 Self : Sized ,
117122 {
@@ -132,25 +137,14 @@ pub unsafe trait AnyTaggedStructure<'a> {
132137 }
133138}
134139
135- /// Non-object-safe variant of [`AnyTaggedStructure`], meaning that a `dyn TaggedStructure` cannot
136- /// exist but as a consequence the [`TaggedStructure::STRUCTURE_TYPE`] associated constant is
137- /// available.
138- ///
139- /// [`AnyTaggedStructure`]s have a [`BaseInStructure::s_type`] field indicating its type, which must
140- /// always match the value of [`TaggedStructure::STRUCTURE_TYPE`].
141- pub unsafe trait TaggedStructure < ' a > : AnyTaggedStructure < ' a > {
142- const STRUCTURE_TYPE : StructureType ;
143- }
144- unsafe impl < ' a , T : TaggedStructure < ' a > > AnyTaggedStructure < ' a > for T { }
145-
146140/// Implemented for every structure that extends base structure `B`. Concretely that means struct
147141/// `B` is listed in its array of [`structextends` in the Vulkan registry][1].
148142///
149143/// Similar to [`TaggedStructure`], all `unsafe` implementers of this trait must guarantee that
150144/// their structure is layout-compatible [`BaseInStructure`] and [`BaseOutStructure`].
151145///
152146/// [1]: https://registry.khronos.org/vulkan/specs/latest/styleguide.html#extensions-interactions
153- pub unsafe trait Extends < ' a , B : AnyTaggedStructure < ' a > > : AnyTaggedStructure < ' a > { }
147+ pub unsafe trait Extends < B > { }
154148
155149/// Holds 24 bits in the least significant bits of memory,
156150/// and 8 bytes in the most significant bits of that memory,
@@ -281,7 +275,7 @@ pub(crate) fn debug_flags<Value: Into<u64> + Copy>(
281275#[ cfg( test) ]
282276mod tests {
283277 use crate :: vk;
284- use crate :: vk:: AnyTaggedStructure as _;
278+ use crate :: vk:: TaggedStructure as _;
285279 use alloc:: vec:: Vec ;
286280 #[ test]
287281 fn test_ptr_chains ( ) {
@@ -343,21 +337,6 @@ mod tests {
343337 assert_eq ! ( chain, chain2) ;
344338 }
345339
346- #[ test]
347- fn test_dynamic_add_to_ptr_chain ( ) {
348- let mut variable_pointers = vk:: PhysicalDeviceVariablePointerFeatures :: default ( ) ;
349- let variable_pointers: & mut dyn vk:: Extends < ' _ , vk:: DeviceCreateInfo < ' _ > > =
350- & mut variable_pointers;
351- let chain = alloc:: vec![ <* mut _>:: cast( variable_pointers) ] ;
352- let mut device_create_info = vk:: DeviceCreateInfo :: default ( ) . push ( variable_pointers) ;
353- let chain2: Vec < * mut vk:: BaseOutStructure < ' _ > > = unsafe {
354- vk:: ptr_chain_iter ( & mut device_create_info)
355- . skip ( 1 )
356- . collect ( )
357- } ;
358- assert_eq ! ( chain, chain2) ;
359- }
360-
361340 #[ test]
362341 fn test_debug_flags ( ) {
363342 assert_eq ! (
0 commit comments