News for hackers. Stuff that matters.
Re:Nibbles of Rust – Restructuring Patterns by metadat on Sunday April 16, 2023 @02:29PM (#35592840)
What determines whether `let Some(y) = x` evaluates to boolean true?
Re:Nibbles of Rust – Restructuring Patterns by asherah on Sunday April 16, 2023 @02:47PM (#35593067)
if 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`
Re:Nibbles of Rust – Restructuring Patterns by jeffdn on Sunday April 16, 2023 @06:38PM (#35594871)
It absolutely works for all patterns!
Re:Nibbles of Rust – Restructuring Patterns by bombela on Sunday April 16, 2023 @02:52PM (#35593126)
The 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") };