reinterpret()

master
Avril 5 years ago
parent 82d6626226
commit 632bd77a58
Signed by: flanchan
GPG Key ID: 284488987C31F630

@ -381,6 +381,18 @@ impl<T> HeapArray<T>
vec.into_boxed_slice() vec.into_boxed_slice()
} }
} }
pub unsafe fn reinterpret<U>(self) -> HeapArray<U>
{
assert!(self.len_bytes() % std::mem::size_of::<U>() == 0);
let output = HeapArray {
size: self.len_bytes() / std::mem::size_of::<U>(),
ptr: self.ptr as *mut U,
drop_check: self.drop_check,
};
std::mem::forget(self);
output
}
} }
impl<T, I> Index<I> for HeapArray<T> impl<T, I> Index<I> for HeapArray<T>
@ -496,5 +508,20 @@ impl<T> From<Vec<T>> for HeapArray<T>
} }
} }
impl<T> From<Box<[T]>> for HeapArray<T>
{
fn from(sl: Box<[T]>) -> Self
{
Self::from_boxed_slice(sl)
}
}
impl<T> From<HeapArray<T>> for Box<[T]>
{
fn from(ha: HeapArray<T>) -> Self
{
ha.into_boxed_slice()
}
}
mod iter; mod iter;
pub use iter::*; pub use iter::*;

Loading…
Cancel
Save