Created
November 18, 2016 10:20
-
-
Save tomasvdw/6a95a3a25aae82b45eb89d118fe3631a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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