返回闭包
返回闭包
错误例子:
fn returns_closure() -> Fn(i32) -> i32 { |x| x + 1 }
正确例子:
fn returns_closure() -> Box<dyn Fn(i32) -> i32> {
Box::new(|x| x + 1)
}
fn main() {
let c = returns_closure();
println!("r = {}", c(1));
//等价于println!("r = {}", (*c)(1)); //解引用多态
println!("Hello, world!");
}