Skip to content

Instantly share code, notes, and snippets.

Created April 23, 2016 17:49
Show Gist options
  • Save anonymous/d040d644c48a28abc38b1196083cf623 to your computer and use it in GitHub Desktop.
Save anonymous/d040d644c48a28abc38b1196083cf623 to your computer and use it in GitHub Desktop.
Shared via Rust Playground
fn get_c() -> Box<FnMut(i32)> {
Box::new(|val: i32| {
println!("value --> {}", val);
})
}
pub fn set_c<F>(mut callback: F)
where F: FnMut(i32)
{
callback(100);
}
fn main() {
let mut cb = get_c();
set_c(|x| cb(x));
set_c(|val: i32| println!("value --> {}", val));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment