Guest User

Untitled

a guest
Jun 18th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.44 KB | None | 0 0
  1. #![feature(nll)]
  2.  
  3. struct X {
  4. x: i32, // read-only, will never change
  5. y: i32, // writeable
  6. }
  7.  
  8. impl X {
  9. fn add(&mut self) {
  10. let x = &self.x;
  11. //let _ = x + 1;
  12.  
  13. self.add2();
  14.  
  15. println!("{}", &x);
  16.  
  17. //let x = &self.x; // borrow No 2
  18. //let _ = x + 2;
  19. }
  20.  
  21. fn add2(&mut self) {
  22. self.x += 123;
  23. }
  24. }
  25.  
  26.  
  27. fn main() {
  28. let mut s = X { x: 1, y: 2 };
  29. s.add();
  30. s.add2();
  31. }
Add Comment
Please, Sign In to add comment