Function slice_copy::clone

source ·
pub fn clone<T>(dst: &mut [T], src: &[T]) -> usizewhere
    T: Clone,
Expand description

Clones as many T as possible from src into dst, returning the number of T cloned. This function is short form for dst.clone_from_slice(src), but accounts for if their lengths are unequal to avoid panics.

Examples

use slice_copy::clone;

let mut l = b"left".to_vec();
let r = b"right".to_vec();

let n = clone(&mut l, &r);

assert_eq!(n, 4);
assert_eq!(l, b"righ");