Created
February 4, 2015 02:50
-
-
Save andydude/212557250d173ced1103 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
#![feature(core)] | |
extern crate "rustc-serialize" as serialize; | |
use std::mem::{size_of, transmute}; | |
use std::slice::bytes::copy_memory; | |
use serialize::hex::ToHex; | |
pub fn transmute_memory<D: Sized, S: Sized>(dst: &mut D, src: &S) { | |
unsafe { | |
let size = size_of::<S>(); | |
assert_eq!(size_of::<D>(), size); | |
let d = transmute::<(&mut D, usize), &mut [u8]>((dst, size)); | |
let s = transmute::<(&S, usize), &[u8]>((src, size)); | |
copy_memory(d, s); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment