头条地址:https://www.ixigua.com/i6775861706447913485
B站地址:https://www.bilibili.com/video/av81202308/
github地址:https://github.com/anonymousGiga/learn_rust
讲解内容返回闭包
错误例子:
fn returns_closure() -> Fn(i32) -> i32 { |x| x + 1 }
正确例子:
fn returns_closure() -> Box i32> {
Box::new(|x| x + 1)
}
fn main() {
let c = returns_closure();
println!("r = {}", c(1));
//等价于println!("r = {}", (*c)(1)); //解引用多态
println!("Hello, world!");
}