Created
July 15, 2018 16:47
-
-
Save rust-play/7ba9ce731bc0828e38e5e410393d6f23 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct Person { | |
x: i32, | |
y: i32, | |
} | |
struct Camera<'a> { | |
person: &'a mut Person, | |
} | |
fn main() { | |
let mut p1 = Person { x: 0, y: 0 }; | |
let mut p2 = Person { x: 1, y: 1 }; | |
let mut c = Camera { person: &mut p1 }; | |
loop { | |
c.person.x += 1; | |
c.person.y += 1; | |
if c.person.x % 2 == 0 { | |
c.person = &mut p1; | |
} else { | |
c.person = &mut p2; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment