Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fcracker79/e51b6bcb123188627a3fdb008e6c38ef to your computer and use it in GitHub Desktop.
Save fcracker79/e51b6bcb123188627a3fdb008e6c38ef to your computer and use it in GitHub Desktop.
rust for loop
struct NiceStructure<'a, T: Iterator<Item=&'a u32>> {
it: T
}
fn f<'a, T: Iterator<Item=&'a u32>>(it: &mut NiceStructure<'a, T>) {
// This does not work: cannot move out of borrowed content
// for x in it.it {
// println!("Element {:?}", x);
// }
// This works
while let Some(x) = it.it.next() {
println!("Element {:?}", x)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment