3 ms·
Can you explain "proper closures"?
by chmod600 3y ago
Can you explain "proper closures"?
- bobbylarrybobby 3y agoI would hazard that this means closures that can capture (shared) state. In Rust, a closure’s data must either be moved into the closure or outlive the closure (dangling pointers etc etc). In most other languages, GC allows closures to keep a handle to any data at all.
- zozbot234 3y agoIf you want a closure to outlive the outside bindings of its captures and thus have shared control over their lifecycle (which is the default behavior of closures in most FP languages) you can easily use Rc<> or Arc<> to that effect. Rust just forces you to be explicit about it.
- whateveracct 3y agoExactly - sharing is the core of FP