3 ms·
> Rust does nested functions well. The compiler can tell whether a nested function references an outer scope and thus needs to be a closure. If the function doe
by dbaupp 12y ago
> Rust does nested functions well. The compiler can tell whether a nested function references an outer scope and thus needs to be a closure. If the function doesn't, an ordinary function is generated.
This isn't quite right; a function declared with `fn` is always a plain function (i.e. never a closure) whether or not it is inside other functions. It's an error to refer to variables in outer scopes.
"Functions" declared with `|...| ...` are always closures, but there's been a few discussions about allowing such functions that capture nothing to be treated as function pointers too (not implemented or formally proposed, yet, though).