3 ms·
What determines whether `let Some(y) = x` evaluates to boolean true?
by metadat 4y ago
What determines whether `let Some(y) = x` evaluates to boolean true?
- bombela 4y agoThe fact that the pattern matches. Here the type being matched is: enum Option<T> { None, Some(T) } let x = Some(42); let Some(y) = x else { panic!("None") };
- asherah 4y agoif x is `Some`, then `y` is set to the inner value and the following block occurs. you can also use this with other enums - i don't remember off the top of my head if it works for all enums, but you can at least also use it with `Result`
- jeffdn 4y agoIt absolutely works for all patterns!