4 ms·
Swift has had ‘guard’ statements since 2015, and it’s the biggest thing I miss when programming in Rust: guard let x = ... else { // must not fall
by NobodyNada 6y ago
Swift has had ‘guard’ statements since 2015, and it’s the biggest thing I miss when programming in Rust:
guard let x = ... else {
// must not fall through, so a return, break, throw, non-returning function call, etc. is required
}
// do something with x
- kibwen 6y agoIn Rust I would just do: let x = match foo { Some(x) => ..., None => return // or break, etc. }; // do something with x (This is assuming that you don't want to propagate an error or panic, which could be more easily done with `foo?` or `foo.unwrap()` respectively.)
- emptysea 6y agoA nice quality of the `guard` in swift is that you can chain multiple conditions, which is harder to do in rust (maybe with some macros a la if_chain?)