Function copy_in_place::copy_in_place[][src]

pub fn copy_in_place<T: Copy, R: RangeBounds<usize>>(
    slice: &mut [T],
    src: R,
    dest: usize
)

Copies elements from one part of a slice to another part of the same slice, using a memmove.

src is the range within the slice to copy from. dest is the starting index of the range within the slice to copy to, which will have the same length as src. The two ranges may overlap. The ends of the two ranges must be less than or equal to slice.len().

Panics

This function will panic if either range exceeds the end of the slice, or if the end of src is before the start.

Examples

Copying four bytes within a slice:

let mut bytes = *b"Hello, World!";

copy_in_place(&mut bytes, 1..5, 8);

assert_eq!(&bytes, b"Hello, Wello!");