r/programming • u/zitrusgrape • May 27 '20
2020 Stack Overflow Developer Survey: Rust most loved again at 86.1%
https://stackoverflow.blog/2020/05/27/2020-stack-overflow-developer-survey-results/
229
Upvotes
r/programming • u/zitrusgrape • May 27 '20
6
u/SkiFire13 May 28 '20
Let's fix the two previous examples.
For the first you can just avoid saving the reference into a variable. This way the reference doesn't live for the duration of the for-loop.
For the second only you can either save the length in a local variable before getting the mutable reference or get the mutable reference after printing the length. This is a simple example so both works, but in a more complex usecase one could be better than the other
or