Skip to content

Instantly share code, notes, and snippets.

@andydude
Created February 4, 2015 00:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andydude/6d24b537128727b44e71 to your computer and use it in GitHub Desktop.
Save andydude/6d24b537128727b44e71 to your computer and use it in GitHub Desktop.
TransmuteMemory
pub fn transmute_memory<T: Sized, U: Sized>(dst: &mut T, src: &U) {
unsafe {
let size = ::std::mem::size_of::<U>();
assert_eq!(::std::mem::size_of::<T>(), size);
::std::ptr::copy_nonoverlapping_memory(
::std::mem::transmute::<&T, *mut T>(dst),
::std::mem::transmute::<&U, *const T>(src),
size);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment