Last active
August 29, 2015 14:02
-
-
Save reem/7dc20a508c4dfdf5a4d4 to your computer and use it in GitHub Desktop.
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
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