You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

32 lines
552 B

pub fn copy_slice<T,S,D>(mut dst: D, src: S) -> usize
where S: AsRef<[T]>,
D: AsMut<[T]>,
T: Clone
{
let mut sz=0;
for (d,s) in dst.as_mut().iter_mut().zip(src.as_ref().iter())
{
*d = s.clone();
sz+=1;
}
sz
}
#[inline]
pub fn reinterpret<T>(src: &T) -> &[u8]
where T: ?Sized
{
unsafe {
std::slice::from_raw_parts(src as *const T as *const u8, std::mem::size_of_val(src))
}
}
pub fn reinterpret_back<T>(src: &[u8]) -> &T
where T: ?Sized + Copy
{
unsafe {
&*(&src[0] as *const u8 as *const T)
}
}