视频地址
头条地址: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<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!");
}
网友评论