Skip to content

Instantly share code, notes, and snippets.

Created September 5, 2016 16:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/47c23561900e6a54f7f3acce95049fe4 to your computer and use it in GitHub Desktop.
Save anonymous/47c23561900e6a54f7f3acce95049fe4 to your computer and use it in GitHub Desktop.
Shared via Rust Playground
pub type uint = u64;
pub fn initialize_with_closure<F>(rules: F) -> uint where F: FnOnce(&mut uint) {
let mut i = 0;
rules(&mut i);
i
}
// equivalently
pub fn initialize_with_closure_explicit<F>(rules: F) -> uint where F: for<'a> FnOnce(&'a mut uint) -> () {
let mut i = 0;
rules(&mut i);
i
}
pub fn main() {
initialize_with_closure(|i: &mut uint| *i = *i + 20);
initialize_with_closure_explicit(|i: &mut uint| *i = *i + 20);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment