malloc_array/reinterpret.rs
1use std::{
2 mem::size_of,
3};
4
5#[inline]
6pub unsafe fn bytes<T,U>(input: T) -> U
7where T: Copy,
8 U: Copy
9{
10 //let _array: [(); size_of::<T>() - size_of::<U>()]; // rust is silly....
11 if size_of::<U>() < size_of::<T>() {
12 panic!("reinterpret: Expected at least {} bytes, got {}.", size_of::<T>(), size_of::<U>());
13 }
14 return *((&input as *const T) as *const U)
15}