Pass and return reference (return ownership)
- An alternate way to handle this situation is to return the vector.
- This way we pass the ownership back to the caller.
examples/threads/pass-and-return-reference/src/main.rs
fn main() { let animals = Vec::from_iter(["mouse", "elephant", "cat", "dog", "giraffe"].map(|animal| animal.to_string())); println!("{:?}", animals); let handle = std::thread::spawn(move || { list_animals(&animals); animals }); let animals = handle.join().unwrap(); println!("{:?}", animals); } fn list_animals(animals: &Vec<String>) { for animal in animals { println!("{}", animal); } }