Skip to content

Instantly share code, notes, and snippets.

@bstrie
Created April 6, 2015 08:08
Show Gist options
  • Save bstrie/b72d8f96406fe1e75dae to your computer and use it in GitHub Desktop.
Save bstrie/b72d8f96406fe1e75dae to your computer and use it in GitHub Desktop.
fn main() {
let make_counter = || {
let mut count = 0;
move || { let so_far = count; count += 1; so_far }
};
let mut a = make_counter();
let mut b = make_counter();
println!("{} {}", a(), a());
println!("{} {}", b(), b());
}
fn make_counter() -> Box<FnMut()->i32> {
let mut count = 0;
Box::new(move || { let so_far = count; count += 1; so_far })
}
fn main() {
let mut a = make_counter();
let mut b = make_counter();
println!("{} {}", a(), a());
println!("{} {}", b(), b());
}
fn make_counter() -> FnMut()->i32 {
let mut count = 0;
move || { let so_far = count; count += 1; so_far }
}
fn main() {
let mut a = make_counter();
let mut b = make_counter();
println!("{} {}", a(), a());
println!("{} {}", b(), b());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment