Guest User

Untitled

a guest
Jul 20th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. // move_semantics3.rs
  2. // Make me compile without adding new lines-- just changing existing lines!
  3. // (no lines with multiple semicolons necessary!)
  4. // Scroll down for hints :)
  5.  
  6. pub fn main() {
  7. let vec0 = Vec::new();
  8.  
  9. let mut vec1 = fill_vec(vec0);
  10.  
  11. println!("{} has length {} content `{:?}`", "vec1", vec1.len(), vec1);
  12.  
  13. vec1.push(88);
  14.  
  15. println!("{} has length {} content `{:?}`", "vec1", vec1.len(), vec1);
  16.  
  17. }
  18.  
  19. fn fill_vec(mut vec: Vec<i32>) -> Vec<i32> {
  20. vec.push(22);
  21. vec.push(44);
  22. vec.push(66);
  23.  
  24. vec
  25. }
  26.  
  27.  
  28.  
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43. // The difference between this one and the previous ones is that the first line
  44. // of `fn fill_vec` that had `let mut vec = vec;` is no longer there. You can,
  45. // instead of adding that line back, add `mut` in one place that will change
  46. // an existing binding to be a mutable binding instead of an immutable one :)
Add Comment
Please, Sign In to add comment