Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #![feature(nll)]
- struct X {
- x: i32, // read-only, will never change
- y: i32, // writeable
- }
- impl X {
- fn add(&mut self) {
- let x = &self.x;
- //let _ = x + 1;
- self.add2();
- println!("{}", &x);
- //let x = &self.x; // borrow No 2
- //let _ = x + 2;
- }
- fn add2(&mut self) {
- self.x += 123;
- }
- }
- fn main() {
- let mut s = X { x: 1, y: 2 };
- s.add();
- s.add2();
- }
Add Comment
Please, Sign In to add comment