Created
July 17, 2014 12:54
-
-
Save yorkie/2747b1616385cef89320 to your computer and use it in GitHub Desktop.
properly use {} in rust
This file contains hidden or 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
fn main() { | |
struct House { owner: Box<Person> } | |
struct Person { age: int } | |
let mut house = box House { | |
owner: box Person {age: 30} | |
}; | |
{ // this pair of braces is required | |
// here the brace is the operator, it release the reference | |
// awesome !!! | |
let mut age= &mut house.owner.age; | |
*age += 10; | |
} | |
print!("{}\n", house.owner.age); // 40 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment