top | item 33453055 (no title) vasilakisfil | 3 years ago you are right, not so useful for Result type, but still, it comes handy for Option types (since None doesn't hold anything). discuss order hn newest etra0|3 years ago Agree, I don't know if it's that useful for `Result<T>`, but for `Option<T>`, there has been a couple of times I've written if foo.is_none() { return; } let foo = foo.unwrap() Now I can do simply let Some(foo_unwrapped) = foo else { return; } which is prettier than the `if let (...)` to just unwrap it IMO. mintplant|3 years ago Without let-else, you could write that as: let foo_unwrapped = match foo { Some(foo_unwrapped) => foo_unwrapped, None => return, }; Not as pretty, but you don't have to unwrap. bonzini|3 years ago For Result it's probably more common to use ?, alternatively you could use let x_result = something; let Ok(x) = x_result else { ... } But I expect that it will be used mostly with Option, as in "else continue" or "else break".
etra0|3 years ago Agree, I don't know if it's that useful for `Result<T>`, but for `Option<T>`, there has been a couple of times I've written if foo.is_none() { return; } let foo = foo.unwrap() Now I can do simply let Some(foo_unwrapped) = foo else { return; } which is prettier than the `if let (...)` to just unwrap it IMO. mintplant|3 years ago Without let-else, you could write that as: let foo_unwrapped = match foo { Some(foo_unwrapped) => foo_unwrapped, None => return, }; Not as pretty, but you don't have to unwrap.
mintplant|3 years ago Without let-else, you could write that as: let foo_unwrapped = match foo { Some(foo_unwrapped) => foo_unwrapped, None => return, }; Not as pretty, but you don't have to unwrap.
bonzini|3 years ago For Result it's probably more common to use ?, alternatively you could use let x_result = something; let Ok(x) = x_result else { ... } But I expect that it will be used mostly with Option, as in "else continue" or "else break".
etra0|3 years ago
mintplant|3 years ago
bonzini|3 years ago