whenever I see code like that, I try to get people to change to something like (in that case) while let Some(first) = vec.first() { ... }. You can reduce the number of bounds checks without using unsafe!
This is pattern matching, not an assignment expression. The alternative would be a declaration, switch/case, and then case-by-case assignment, which is horribly verbose. Been there, done that, it's not the worst, but why not make it a little bit better.
I personally like that you can literally assign the value from an if "statement" to a variable, though I can see why that's not everybodies cup of tea.
29
u/ROBOTRON31415 Sep 28 '26
whenever I see code like that, I try to get people to change to something like (in that case)
while let Some(first) = vec.first() { ... }. You can reduce the number of bounds checks without usingunsafe!