3 ms·
The awkwardness is because use of `self.whatever` in closures borrows `self` as a whole instead of just the `whatever` part. The good news is that Rust is going
by pornel 5y ago
The awkwardness is because use of `self.whatever` in closures borrows `self` as a whole instead of just the `whatever` part. The good news is that Rust is going to fix this soon:
https://blog.rust-lang.org/2021/05/11/edition-2021.html#disjoint-capture-in-closures https://blog.rust-lang.org/2021/05/11/edition-2021.html#disj...
- sodality2 5y agoThank you so much! that's very interesting.
- Arnavion 5y agoIf the problem is as pornel described, you can work around it by creating the borrow of self.whatever outside the closure. Instead of: foo(|| { bar(&self.whatever); }); ... do: let whatever = &self.whatever; foo(|| { bar(whatever); }); To avoid leaking `whatever` into the scope, there's an idiom that looks like this: foo({ let whatever = &self.whatever; || { bar(whatever); } });
- sodality2 5y agoYeah that's what I've had to do, it just seemed like an oversight tbh. Maybe the idea is to not keep the entire GUI state in a single object though, but it's the one time learning rust that I thought "hey that doesn't make sense". which really speaks to Rust's strengths, rather than its weaknesses. Can't wait for 2021
- brundolf 5y agoOh thank god. This has been so annoying in the past