I can’t help but suspect it doesn’t offer much and you may as well just use match
statements for whenever you want pattern matching, however many times it might be slightly more verbose than what you could do with if let
.
I feel like I’d easily miss that pattern matching was happening with if let
but will always know with match
what’s happening and have an impression of what’s happening just from the structure of the code.
I would say it’s very useful when you are looking for one specific pattern, which happens a lot with
Option<T>
. Plus, being able to chain it inif / else if / else
chains helps with organizing the code. It generally doesn’t grow as deep as withmatch
.That said,
match
is fantastic and it’s totally fine to prefer using it.if let
andlet else
are there for those cases when you tend to discard or not need to use the other values than the matched one. How often that happens depends on what you are doing.