Function std::intrinsics::copy
[−]
[src]
pub unsafe extern "rust-intrinsic" fn copy<T>(src: *const T, dst: *mut T, count: usize)
Copies count * size_of<T> bytes from src`srcto` to dst`dst`. The source
and destination may overlap.
copy`copyis semantically equivalent to C'smemmove`.
Safety
Care must be taken with the ownership of src`srcand` and dst`dst. This method semantically moves the values ofsrcinto` into dst`dst. However it does not drop the contents ofdst, or prevent the contents ofsrc`
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: usize) -> Vec<T> { let mut dst = Vec::with_capacity(elts); dst.set_len(elts); ptr::copy(ptr, dst.as_mut_ptr(), elts); dst } }use std::ptr; unsafe fn from_buf_raw<T>(ptr: *const T, elts: usize) -> Vec<T> { let mut dst = Vec::with_capacity(elts); dst.set_len(elts); ptr::copy(ptr, dst.as_mut_ptr(), elts); dst }