Function std::intrinsics::copy_memoryUnstable
[-] [+]
[src]
pub unsafe fn copy_memory<T>(dst: *mut T, src: *const T, count: usize)
Copies count * size_of<T>
bytes from src
to dst
. The source
and destination may overlap.
copy_memory
is semantically equivalent to C's memmove
.
Safety
Care must be taken with the ownership of src
and dst
.
This method semantically moves the values of src
into dst
.
However it does not drop the contents of dst
, or prevent the contents of src
from being dropped or used.
Examples
Efficiently create a Rust vector from an unsafe buffer:
fn main() { use std::ptr; unsafe fn from_buf_raw<T>(ptr: *const T, elts: uint) -> Vec<T> { let mut dst = Vec::with_capacity(elts); dst.set_len(elts); ptr::copy_memory(dst.as_mut_ptr(), ptr, elts); dst } }use std::ptr; unsafe fn from_buf_raw<T>(ptr: *const T, elts: uint) -> Vec<T> { let mut dst = Vec::with_capacity(elts); dst.set_len(elts); ptr::copy_memory(dst.as_mut_ptr(), ptr, elts); dst }