Skip to content

Instantly share code, notes, and snippets.

@gong023
Last active August 29, 2015 14:07
Show Gist options
  • Save gong023/a737c3cb0322acd555db to your computer and use it in GitHub Desktop.
Save gong023/a737c3cb0322acd555db to your computer and use it in GitHub Desktop.
fn hoge() -> ||:'static -> bool {
let a = || { true };
return a;
}
fn main() {
let a = hoge();
a();
}
#![feature(unboxed_closures, unboxed_closure_sugar)]
use std::collections::HashMap;
fn main() {
let foo = bar(8);
println!("Trying `foo` with 4: {:d}", foo.call((4,)));
println!("Trying `foo` with 8: {:d}", foo.call((8,)));
println!("Trying `foo` with 13: {:d}", foo.call((13,)));
}
fn bar(x: int) -> Box<|&: int| -> int> {
box |&: n: int| -> int {
if n < x { return n }
x
}
}
fn property(x: uint) -> Box<|&:|:'static -> int> {
let mut h = HashMap::new();
h.insert(1u, 1i);
h.insert(2u, 2i);
return box |&:| -> int { h.get_copy(&x) }
}
~
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment