You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If we match a Result<x,y> , and we see that one of the results is ignored via Ok(_) => {} or Err(_bla) => {}, can we somehow simplify this to _ => {} ?
The idea is that since we know that Result will either return Ok or Error, no other values are possible, which is why I think
match x {Ok(_) => {},Err(a) => {do_something(a)},}
is equivalent to
match x {Err(a) => {do_something(a)},
_ => {},}
however, the second example will trigger single_match lint while the first one will not.
This makes sense for Result, whose definition is guaranteed not to change. But it might not be an improvement for other enums.
When a new variant is added to an enum, the explicit match will fail to compile, whereas the catch-all match will pass silently. This can hide mistakes where you've forgotten to handle the new variant.
If we match a Result<x,y> , and we see that one of the results is ignored via
Ok(_) => {}
orErr(_bla) => {}
, can we somehow simplify this to_ => {}
?The idea is that since we know that Result will either return Ok or Error, no other values are possible, which is why I think
is equivalent to
however, the second example will trigger single_match lint while the first one will not.
code sample:
Does this make sense?
The text was updated successfully, but these errors were encountered: