std-method
slice::clone_from_slice
Replace the elements of an equally long destination by cloning from a source. Unlike copy_from_slice, it supports Clone types that are not Copy. Expected stdout (not executed): ["north", "south"] Common mistake: Expecting the destination to resize automatically when lengths differ.
Formal Syntax & Structure
rust syntaxrust
destination.clone_from_slice(source)Working Example
Example Snippetrust
fn main() { let source = [String::from("north"), String::from("south")]; let mut target = [String::new(), String::new()]; target.clone_from_slice(&source); println!("{target:?}");}