3 ms·
Because you want the buffer to go out of scope after the last iteration of the loop. Motivating that requires bringing in more rust - It could be as simple as w
by dgacmu 2y ago
Because you want the buffer to go out of scope after the last iteration of the loop. Motivating that requires bringing in more rust - It could be as simple as wanting to reuse the variable name later, but more likely it would be because you were using something that had a reference that you wanted to go away so you could borrow it again without the borrow checker yelling at you.
- auggierose 2y agoOk, then the nested scope is indeed exactly what you want. I don't see how obfuscating this purpose and trying to rely on obscure compiler optimisations and intricate semantics would be a good idea.
- dgacmu 2y agoBecause, as someone else noted, it might be hidden for you because you're using something that's inside another function, macro, struct, etc.
- auggierose 2y agoYes, that is a valid reason. If I get that optimisation for free, why not? I still would not rely on that optimisation, though. If I think this could be an actual bottle neck, I would make the shared buffer explicit in my code.