logoalt Hacker News

kace91last Monday at 1:00 AM1 replyview on HN

I like rust matching for this reason: You need to cover all branches.

In fact, not using a default (the else clause equivalent) is ideal if you can explicitly cover all cases, because then if the possibilities expand (say a new value in an enum) you’ll be annoyed by the compiler to cover the new case, which might otherwise slip by.


Replies

ueckerlast Monday at 9:49 AM

And I like using enums in C ;-) The compiler tells you to cover all branches.

https://godbolt.org/z/bY1P9Kx7n

show 2 replies