Advertisement
Guest User

Untitled

a guest
Mar 24th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.43 KB | None | 0 0
  1. fn wtf(vector: &mut Vec<i32>) { // mutable borrow starts here
  2. vector.push(20)
  3. } // mutable borrow also ends here
  4.  
  5.  
  6. fn main() {
  7. let mut p: Vec<i32> = vec![1, 2, 3];
  8. {
  9. let x = &mut p; // lifetime of mutable borrow starts here
  10. x.push(42);
  11. } // life-time of x ends here
  12.  
  13. wtf(&mut p);
  14.  
  15. println!("{:?}", p); // & to P...we have one mutable ref, one immutable ref
  16. //-- why no compile time error???
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement