3 ms·
Using "if let" is generally preferred style when there's only a single case that needs to be handled. (And I suspect that now that "if let ... else" is availabl
by khuey 4y ago
Using "if let" is generally preferred style when there's only a single case that needs to be handled. (And I suspect that now that "if let ... else" is available that that will become the preferred style for handling two cases.)
- fasterthanlime 4y agoYeah, clippy will yell at you if you use a match with a single arm - I personally don't hate matches with a single arm, but I'd rather not fight clippy (ie. come up with my own clippy config, enforce it onto every project I maintain etc.)
- ratmice 4y agoI've hit this warning a few times where I expect to add additional match arms to be added in the future, always bugs me that clippy in that case steers you towards some change you know you'll end up undoing.
- pitaj 4y ago> And I suspect that now that "if let ... else" is available that that will become the preferred style for handling two cases. if let Pattern(binding) = thing { ... } else { ... } has been available for a long time. What was recently stabilized is let Pattern(binding) = thing else { ... }; which is syntax sugar for let binding = if let Pattern(binding) { binding } else { ... }; And facilitates easier unwrapping in early exit or default scenarios, without an extra level of indentation.
- khuey 4y agoYes, you're right of course. That's what I get for commenting while not fully awake :)