在Rustprimer一书,具体见:
https://rustcc.gitbooks.io/rustprimer/content/quickstart/function-method.html
其中:
fn factory(x: i32) -> Box<Fn(i32) -> i32> {
Box::new(move |y| x + y)
}
//为什么这里并不需要拆箱?
fn main() {
let box_fn = factory(1i32);
let b0 = box_fn(2i32) * 2; //不需要拆箱?
let b1 = (*box_fn)(2i32) * 2;
let b2 = (&box_fn)(2i32) * 2;
println!("{}, {}, {}", b0, b1, b2);//6,6,6
}