Closed
Description
Unboxed closures (#8622) would capture by-value, and there would be no need to add syntax for a by-reference capture. Rust's references are first-class values, unlike C++, so it's trivial to capture a reference by-value.
This would create an unboxed closure (f
) with the same size as b
:
let b = 5;
let f = |a| a + b;
A by-reference capture would need to be explicit:
let b = &mut 5;
let f = |a| *b = a;
I think we should consider changing the current rules, to permit dropping in unboxed closures as a backwards compatible enhancement in the future.
Metadata
Metadata
Assignees
Labels
No labels