Allow typecast for VkMappedMemory
This commit is contained in:
parent
92b4f55192
commit
dee3fd1213
1 changed files with 18 additions and 3 deletions
|
@ -1,5 +1,7 @@
|
|||
use core::slice::{Iter, IterMut};
|
||||
use std::mem;
|
||||
use std::ops::{Index, IndexMut};
|
||||
use std::rc::Rc;
|
||||
use std::{fmt, fmt::Debug};
|
||||
|
||||
pub struct VkMappedMemory<'a, T>
|
||||
|
@ -8,7 +10,7 @@ where
|
|||
{
|
||||
data: &'a mut [T],
|
||||
|
||||
unmap: Option<Box<dyn Fn()>>,
|
||||
unmap: Option<Rc<dyn Fn()>>,
|
||||
}
|
||||
|
||||
impl<'a, T: Clone> VkMappedMemory<'a, T> {
|
||||
|
@ -18,9 +20,9 @@ impl<'a, T: Clone> VkMappedMemory<'a, T> {
|
|||
|
||||
pub fn set_unmap<F>(&mut self, f: F)
|
||||
where
|
||||
F: Fn() + 'static,
|
||||
F: Fn() + Clone + 'static,
|
||||
{
|
||||
self.unmap = Some(Box::new(f));
|
||||
self.unmap = Some(Rc::new(f));
|
||||
}
|
||||
|
||||
pub fn copy(&mut self, data: &[T]) {
|
||||
|
@ -34,6 +36,19 @@ impl<'a, T: Clone> VkMappedMemory<'a, T> {
|
|||
pub fn iter_mut(&mut self) -> IterMut<'_, T> {
|
||||
self.data.iter_mut()
|
||||
}
|
||||
|
||||
pub unsafe fn reinterpret<U: Clone>(self) -> VkMappedMemory<'a, U> {
|
||||
debug_assert_eq!(mem::size_of::<U>(), mem::size_of::<T>());
|
||||
|
||||
let mem = VkMappedMemory {
|
||||
data: mem::transmute(self.data as *mut [T]),
|
||||
unmap: self.unmap.clone(),
|
||||
};
|
||||
|
||||
mem::forget(self);
|
||||
|
||||
mem
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, T: Clone> Index<usize> for VkMappedMemory<'a, T> {
|
||||
|
|
Loading…
Reference in a new issue