vulkan/handle: Allow passing borrows of slices as mutable pointers

This commit is contained in:
Marijn Suijten 2023-11-27 14:12:38 +01:00
parent 98aed74afc
commit 93dcb3e934
No known key found for this signature in database
GPG key ID: 23E7CB3F180C39F2

View file

@ -20,28 +20,54 @@ pub type VulkanHandleTypedef = GstVulkanHandleTypedef;
// }
// }
impl<'a> ToGlibContainerFromSlice<'a, *const *mut GstVulkanHandle> for &'a VulkanHandle {
// impl<'a> ToGlibContainerFromSlice<'a, *const *mut GstVulkanHandle> for &'a VulkanHandle {
// type Storage = &'a [Self];
// fn to_glib_none_from_slice(t: Self::Storage) -> (*const *mut GstVulkanHandle, Self::Storage) {
// skip_assert_initialized!();
// assert_eq!(
// std::mem::size_of::<Self>(),
// std::mem::size_of::<*mut GstVulkanHandle>()
// );
// let t_ptrs: &[*mut GstVulkanHandle] = unsafe { std::mem::transmute(t) };
// (t_ptrs.as_ptr(), t)
// }
// fn to_glib_container_from_slice(
// _t: Self::Storage,
// ) -> (*const *mut GstVulkanHandle, Self::Storage) {
// skip_assert_initialized!();
// unimplemented!("Consumer can't free *const pointer")
// }
// fn to_glib_full_from_slice(_t: &[Self]) -> *const *mut GstVulkanHandle {
// skip_assert_initialized!();
// unimplemented!("Consumer can't free *const pointer")
// }
// }
impl<'a> ToGlibContainerFromSlice<'a, *mut *mut GstVulkanHandle> for &'a VulkanHandle {
type Storage = &'a [Self];
fn to_glib_none_from_slice(t: Self::Storage) -> (*const *mut GstVulkanHandle, Self::Storage) {
fn to_glib_none_from_slice(t: Self::Storage) -> (*mut *mut GstVulkanHandle, Self::Storage) {
skip_assert_initialized!();
assert_eq!(
std::mem::size_of::<Self>(),
std::mem::size_of::<*mut GstVulkanHandle>()
);
let t_ptrs: &[*mut GstVulkanHandle] = unsafe { std::mem::transmute(t) };
(t_ptrs.as_ptr(), t)
(t_ptrs.as_ptr().cast_mut(), t)
}
fn to_glib_container_from_slice(
_t: Self::Storage,
) -> (*const *mut GstVulkanHandle, Self::Storage) {
) -> (*mut *mut GstVulkanHandle, Self::Storage) {
skip_assert_initialized!();
unimplemented!("Consumer can't free *const pointer")
unimplemented!("Consumer can't free *mut pointer")
}
fn to_glib_full_from_slice(_t: &[Self]) -> *const *mut GstVulkanHandle {
fn to_glib_full_from_slice(_t: &[Self]) -> *mut *mut GstVulkanHandle {
skip_assert_initialized!();
unimplemented!("Consumer can't free *const pointer")
unimplemented!("Consumer can't free *mut pointer")
}
}