Advertisement
Guest User

Untitled

a guest
Oct 21st, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. fn main() {
  2. let my_arr_a: [usize; 5] = [1,2,3,4,5];
  3. let my_arr_b: [usize; 5] = my_arr_a; // Since `usize` implements `Copy`, the containing array implements `Copy` so we don't need to clone it and the value will automatically be copied
  4. println!("v {}", my_arr_a[0]);
  5.  
  6. let my_arr_a: [String; 3] = ["abc".to_owned(), "def".to_owned(), "hij".to_owned()];
  7. let my_arr_b: [String; 3] = my_arr_a.clone(); // Since `String` does not implement `Copy` but does implement `Clone`, we need to call `Clone` on the containing array; otherwise we're moving the value
  8. println!("v {}", my_arr_a[0]);
  9. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement