Skip to content

Instantly share code, notes, and snippets.

@tomasvdw
Created November 18, 2016 10:20
Show Gist options
  • Save tomasvdw/6a95a3a25aae82b45eb89d118fe3631a to your computer and use it in GitHub Desktop.
Save tomasvdw/6a95a3a25aae82b45eb89d118fe3631a to your computer and use it in GitHub Desktop.
struct MyData { pub x: usize }
fn process<F>(mut callback: F)
where F : FnMut(MyData) {
for n in 0..10 {
let data = MyData { x: n };
callback(data);
}
}
fn main() {
let mut list = Vec::new();
process(|data| {
println!("{:?}", data.x);
list.push(data.x);
});
println!("{:?}", list);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment