Re:A lambda is not necessarily a closure
by Manishearth on Tuesday February 09, 2016 @04:14AM
(#11064109)
> You'd like for this to optimize down to a function call, without saving any state from the outer scope. Don't know if Rust does this yet.
It does. Rust closures translate to a stack struct containing the capture and a method call on that struct. In this case, the struct is zero-sized, so it doesn't exist, so it's just a function call. Additionally, unwrap_or_else will probably be monomorphised and then inlined, so there will be no call at all.
It does. Rust closures translate to a stack struct containing the capture and a method call on that struct. In this case, the struct is zero-sized, so it doesn't exist, so it's just a function call. Additionally, unwrap_or_else will probably be monomorphised and then inlined, so there will be no call at all.
"closure" is just the term for the syntax.
> You can't pass a pointer to a function.
Sure you can.
Both functions and closures implement the Fn* traits