プログラミング言語Rustのラムダ式(lambda expression)は、トレイトFnOnce / FnMut / Fn を実装(impl)したクロージャ(closure)を作り出す、一種の糖衣構文(syntax sugar)として機能する。
Closure implementation
Rust's implementation of closures is a bit different than other languages. They are effectively syntax sugar for traits. You'll want to make sure to have read the traits chapter before this one, as well as the chapter on trait objects.(snip)
The
https://doc.rust-lang.org/book/closures.html|| {}
syntax for closures is sugar for these three traits. Rust will generate a struct for the environment,impl
the appropriate trait, and then use it.
関連URL