Created
February 4, 2015 00:39
-
-
Save andydude/6d24b537128727b44e71 to your computer and use it in GitHub Desktop.
TransmuteMemory
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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