4 ms·
Why would there be cycles? Rust captures closure environments however you like. You can copy them, share them, reference them, whatever.
by Retra 9y ago
Why would there be cycles? Rust captures closure environments however you like. You can copy them, share them, reference them, whatever.
- kazinator 9y agoWhy would be there be cycles when you have closures? Because a function's environment can end up having a reference back to the same function. This can be set up without assignment, given just a lambda operator. Hint: look in domain name in the URL in the browser address bar.
- viraptor 9y agoIf you used it in a way that allows the closure to escape the scope, you'd get one of the "foo can't outlive bar in score ...". (On a mobile, can't write an example easily)
- deleted 9y ago[deleted]
- kazinator 9y agoIf I can't have escaping closures, I want to be working in C.
- bombela 9y agoyou can have "escaping" closure. But you cannot return something that outlives it's lifetime. So the closure must own data, not merely refer to it. The online Rust book should habe the details.
- viraptor 9y agoYou can use unsafe if you want to feel like working with C :-) There's nothing stopping you from doing things you know are correct. You just sometimes need to tell the compiler that you know better and guarantee that the code is fine.
- pjmlp 9y agoA good example are event handlers on GUI widgets.