3 ms·
Well not in the article but I saw somebody doing a guard clause that I started to copy. i.e. ``` let min_id = if let Some(id) = foo()? { id } else { return;
by lesuorac 4y ago
Well not in the article but I saw somebody doing a guard clause that I started to copy.
i.e.
```
let min_id = if let Some(id) = foo()? { id } else { return; }
...
let bar = if let Some(bar) = baz()? { bar } else { return; }
..
// vs
if let Some(id) = foo()? {
...
if let Some(bar) = baz()? {
..
}}
```
It's nice to also do `if let (Some(x), Some(y)) = ...` but sometimes you need the result of `x` to do a few things before you can get `y` (or maybe don't went to evaluate `y` depending on `x`).
---
I like the `where` syntax more than the example formatting.
```
fn x<T>(t: T) where T: Foo {}
```
- cormacrelf 4y agoHave you heard about let-else? It’s a recent syntax addition. That example translates as let Some(min_id) = foo() else { return }; // continue coding at same indent