Skip to content

Instantly share code, notes, and snippets.

@reem
Last active August 29, 2015 14:02
Show Gist options
  • Save reem/7dc20a508c4dfdf5a4d4 to your computer and use it in GitHub Desktop.
Save reem/7dc20a508c4dfdf5a4d4 to your computer and use it in GitHub Desktop.
fn main() {
#[deriving(Show)]
struct Foo {
a: i32
}
let mut test:Vec<Foo> = Vec::new();
test.push(Foo { a: 1 });
test.push(Foo { a: 3 });
test.push(Foo { a: 2 });
{
let mut res = &mut Foo { a: 0 };
for t in test.mut_iter() {
if t.a > res.a {
res = t;
}
}
res.a = 10;
} // res is destroyed here, so you can now borrow test again
println!("{}", test);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment