6 ms·
Personally, I give closures in Rust to be much less awkward than lambdas in C++. What issues do you have with them?
by saghm 10y ago
Personally, I give closures in Rust to be much less awkward than lambdas in C++. What issues do you have with them?
- IshKebab 10y agoIt's the combination of the lambdas and the borrowing system. You have to move all resources into them and then you can't use them from anywhere else. What I mean is, it's not the closures exactly that are the problem. It's just that closures are one of the times it would be really really convenient if you could have multiple mutable references to something. You end up having to use `Rc<RefCell<>>` as described here: http://gtk-rs.org/tuto/closures#using-non-gtk-rs-object-into-a-gtk-rs-closure http://gtk-rs.org/tuto/closures#using-non-gtk-rs-object-into... This is also mentioned in the Tock PDF: https://sing.stanford.edu/site/publications/levy-plos15-tock.pdf https://sing.stanford.edu/site/publications/levy-plos15-tock... in section 3.2. I'm not really sure how they overcame that in Tock. I guess using RefCell? Anyway it all seems very awkward.
- saghm 10y agoAh, I see. I think my perspective tends to be outside the norm when it comes to things like this, since I learned Rust before learning C++, so the Rust way feels "natural", for lack of a better word. I find myself wishing I could do things the Rust way in C++ far more often than vice-versa.
- steveklabnik 10y agoThey invented some new interior mutability things, if you check the recent Tock discussion on HN via search you should see some things, and a link to Reddit about it.