3 ms·
> Yeah, I feel like the vast majority of the time this would be better handled by splitting out that block into a function. It's a nice idea, and Rust supports
by zozbot234 4y ago
> Yeah, I feel like the vast majority of the time this would be better handled by splitting out that block into a function.
It's a nice idea, and Rust supports "local" fn definitions inside blocks so it would be quite elegant as well.
- edflsafoiewq 4y agoThe borrow checker is "smarter" within a single function body though, so factoring code into a separate function is not necessarily as easy as in other languages.
- Ar-Curunir 4y agoYou can use it with a closure to get the best of both worlds
- saghm 4y agoI ran into this issue years ago (possibly even before labeled exit from loops or even NLL, although I'd have to dig through some old code to confirm this). I had some logic that I wanted to short-circuit, but moving everything to a separate method call would have required an extra borrow that would not have been allowed. I don't think that I'll end up needing to use this feature much, but I'm glad to finally have it as an option for the rare cases when it will improve the readability of my code.