4 ms·
In the context of this blog post, an example with Result would be more suitable though. if let Ok(value) = fun_can_fail() { // success, use value
by brabel 2y ago
In the context of this blog post, an example with Result would be more suitable though.
if let Ok(value) = fun_can_fail() {
// success, use value
} else {
// error, but we don't care which one when using if-let
}
- Expurple 2y agoThis isn't the only pattern that `if let` is suitable for. It's often used without an `else`, as a syntax sugar for match value { the_only_case_that_we_care_about => { // Do something with the bound value. }, _ => {}, // Don't do anything, we don't care about the other cases at all. }