I'm working with raw pointers in Rust and am trying to copy an area of memory from one place to another. I've got it successfully copying memory over, but only using a for loop and copying each byte individually using an offset of the pointer. I can't figure out how to do this more efficiently, i.e. as a single copy of a string of bytes, can anyone point me in the right direction?
fn copy_block_memory<T>(src: *const T, dst: *mut u8) {
let src = src as *const u8;
let size = mem::size_of::<T>();
unsafe {
let bytes = slice::from_raw_parts(src, size);
for i in 0..size as isize {
ptr::write(dst.offset(i), bytes[i as usize]);
}
}
}