How to copy a slice optimally?

How to copy content from one slice to another properly and optimally?

fn copy<'a, 'b, T>(src: &'a [T], dst: &'b [T]) {
    assert!(src.len() == dst.len());
    *dst = *src;
}

It is implied that both slices always have the same length.

Playground.

Are you sure you can do better then <[T]>::copy_from_slice?

7 Likes

That is what I had been looking for. Thank you!