Created
September 5, 2016 16:16
-
-
Save anonymous/47c23561900e6a54f7f3acce95049fe4 to your computer and use it in GitHub Desktop.
Shared via Rust Playground
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
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