頭條地址:https://www.ixigua.com/i677586170644791348...
B站地址:https://www.bilibili.com/video/av81202308/
github地址:https://github.com/anonymousGiga/learn_rus...
返回閉包
錯誤例子:
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!");
}
本作品採用《CC 協議》,轉載必須註明作者和本文連結