function - 我可以有一个在 Rust 中不被类型化为闭包的匿名函数吗?

标签 function lambda closures rust anonymous-function

我使用的是 1.6.0(稳定版),但任何启用此功能或我可以观看/跟踪的 future /夜间功能也很酷。

理论上我想要什么(为简洁起见进行了简化):

let a:fn(&lib_plotMote::mask::Mask) -> bool = {fn(_)->true};

我得到的最接近的:

let a:fn(&lib_plotMote::mask::Mask) -> bool = { fn anon(_:&Mask)->bool{true}; anon };

最佳答案

没有。

闭包 Rust 的“匿名函数”特性。

也就是说,您可以稍微减少您所拥有的冗余:

let a: fn(_) -> _ = { fn anon(_: &Mask) -> bool { true }; anon };

关于function - 我可以有一个在 Rust 中不被类型化为闭包的匿名函数吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35388729/

相关文章:

c - 将指针的结构数组作为函数参数传递?

python - 使用 "min"的函数的水平集

arrays - bash:如何删除函数内的列表条目?

c# - 当外键为空时,使用 Lambda 表达式在 List<T> 中排序

javascript - 我不确定如何解决教科书中的这个匿名函数闭包问题

javascript - 基本 Javascript/jQuery 数学游戏 : Why can't I evaluate the second time I run this function?

c# - 定义一个lambda函数并立即执行

vb.net - VB.NET 中的 lambda 表达式...我做错了什么?

generics - 参数类型 `T` 可能活得不够长

scala - 调用匿名闭包