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>
`count * size_ofbytes from
` bytes from src
`srcto
` to dst
`dst`. The source
and destination may overlap.
copy
`copyis semantically equivalent to C's
` is semantically equivalent to C's memmove
`memmove`.
Safety
Care must be taken with the ownership of src
`srcand
` and dst
`dst. This method semantically moves the values of
`.
This method semantically moves the values of src
`srcinto
` into dst
`dst. However it does not drop the contents of
`.
However it does not drop the contents of dst
`dst, or prevent the contents of
`, or prevent the contents of src
`src`
from being dropped or used.
Examples
Efficiently create a Rust vector from an unsafe buffer:
#![feature(core)] 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 }