Use repr transparent for builders

This commit is contained in:
Maik Klein 2019-03-03 14:33:19 +01:00
parent d6a6aa310e
commit 38fe16f6c7
3 changed files with 2961 additions and 4072 deletions

View file

@ -209,12 +209,8 @@ pub struct PhysicalDeviceGpaPropertiesAmdBuilder<'a> {
marker: ::std::marker::PhantomData<&'a ()>, marker: ::std::marker::PhantomData<&'a ()>,
} }
pub unsafe trait ExtendsPhysicalDeviceGpaPropertiesAmd { pub unsafe trait ExtendsPhysicalDeviceGpaPropertiesAmd {
unsafe fn as_ptr_mut(&mut self) -> *mut BaseOutStructure;
} }
unsafe impl ExtendsPhysicalDeviceProperties2 for PhysicalDeviceGpaPropertiesAmd { unsafe impl ExtendsPhysicalDeviceProperties2 for PhysicalDeviceGpaPropertiesAmd {
unsafe fn as_ptr_mut(&mut self) -> *mut BaseOutStructure {
::std::mem::transmute(self)
}
} }
impl<'a> ::std::ops::Deref for PhysicalDeviceGpaPropertiesAmdBuilder<'a> { impl<'a> ::std::ops::Deref for PhysicalDeviceGpaPropertiesAmdBuilder<'a> {
type Target = PhysicalDeviceGpaPropertiesAmd; type Target = PhysicalDeviceGpaPropertiesAmd;
@ -655,12 +651,8 @@ pub struct PhysicalDeviceWaveLimitPropertiesAmdBuilder<'a> {
marker: ::std::marker::PhantomData<&'a ()>, marker: ::std::marker::PhantomData<&'a ()>,
} }
pub unsafe trait ExtendsPhysicalDeviceWaveLimitPropertiesAmd { pub unsafe trait ExtendsPhysicalDeviceWaveLimitPropertiesAmd {
unsafe fn as_ptr_mut(&mut self) -> *mut BaseOutStructure;
} }
unsafe impl ExtendsPhysicalDeviceProperties2 for PhysicalDeviceWaveLimitPropertiesAmd { unsafe impl ExtendsPhysicalDeviceProperties2 for PhysicalDeviceWaveLimitPropertiesAmd {
unsafe fn as_ptr_mut(&mut self) -> *mut BaseOutStructure {
::std::mem::transmute(self)
}
} }
impl<'a> ::std::ops::Deref for PhysicalDeviceWaveLimitPropertiesAmdBuilder<'a> { impl<'a> ::std::ops::Deref for PhysicalDeviceWaveLimitPropertiesAmdBuilder<'a> {
type Target = PhysicalDeviceWaveLimitPropertiesAmd; type Target = PhysicalDeviceWaveLimitPropertiesAmd;
@ -677,7 +669,7 @@ impl<'a> PhysicalDeviceWaveLimitPropertiesAmdBuilder<'a> {
T: ExtendsPhysicalDeviceWaveLimitPropertiesAmd, T: ExtendsPhysicalDeviceWaveLimitPropertiesAmd,
{ {
unsafe { unsafe {
let next_ptr = next.as_ptr_mut(); let next_ptr = next as *mut _ as *mut BaseOutStructure;
(*next_ptr).p_next = self.inner.p_next as _; (*next_ptr).p_next = self.inner.p_next as _;
self.inner.p_next = next_ptr as _; self.inner.p_next = next_ptr as _;
} }

File diff suppressed because it is too large Load diff

View file

@ -1601,7 +1601,7 @@ pub fn derive_setters(
/// chain will look like `A -> D -> B -> C`. /// chain will look like `A -> D -> B -> C`.
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: &'a mut T) -> #name_builder<'a> {
unsafe{ unsafe{
let next_ptr = next.as_ptr_mut(); let next_ptr = next as *mut T as *mut BaseOutStructure;
(*next_ptr).p_next = self.inner.p_next as _; (*next_ptr).p_next = self.inner.p_next as _;
self.inner.p_next = next_ptr as _; self.inner.p_next = next_ptr as _;
} }
@ -1617,7 +1617,6 @@ pub fn derive_setters(
let next_trait = if has_next && _struct.extends.is_none() { let next_trait = if has_next && _struct.extends.is_none() {
quote! { quote! {
pub unsafe trait #extends_name { pub unsafe trait #extends_name {
unsafe fn as_ptr_mut(&mut self) -> *mut BaseOutStructure;
} }
} }
} else { } else {
@ -1628,14 +1627,8 @@ pub fn derive_setters(
let impl_extend_trait = if let Some(next_extends) = next_extends { let impl_extend_trait = if let Some(next_extends) = next_extends {
quote! { quote! {
unsafe impl #next_extends for #name_builder<'_> { 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 impl #next_extends for #name {
unsafe fn as_ptr_mut(&mut self) -> *mut BaseOutStructure{
::std::mem::transmute(self)
}
} }
} }
} else { } else {
@ -1652,6 +1645,7 @@ pub fn derive_setters(
} }
} }
#[repr(transparent)]
pub struct #name_builder<'a> { pub struct #name_builder<'a> {
inner: #name, inner: #name,
marker: ::std::marker::PhantomData<&'a ()>, marker: ::std::marker::PhantomData<&'a ()>,