4 ms·
I ran into this the other day, and it took me a moment to realise that I could just use `matches!`: // want to do this if not let Some("pattern") = val
by safarimonkey 6y ago
I ran into this the other day, and it took me a moment to realise that I could just use `matches!`:
// want to do this
if not let Some("pattern") = val {
doSomething();
}
// can instead do
if !matches!(val, Some("pattern")) {
doSomething();
}
- NobodyNada 6y agoThat won’t allow extracting a value from the optional though, will it? i.e. I can’t do this something along the lines of: if !matches!(val, Some(let x))
- safarimonkey 6y agoIndeed not, so it's not a full replacement. I'm not entirely sure that I like the idea of an "if let" variant creating bindings that escape the visual block, but I'd probably get over it.