Skip to content

Instantly share code, notes, and snippets.

@yorkie
Created July 17, 2014 12:54
Show Gist options
  • Save yorkie/2747b1616385cef89320 to your computer and use it in GitHub Desktop.
Save yorkie/2747b1616385cef89320 to your computer and use it in GitHub Desktop.
properly use {} in rust
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