Elektrine lite

← Feed

@andy_f@fosstodon.org

2026-02-07 20:27 UTC

@osunderdog It might help to break it down into parts. First, `let Some(x) = my_iter.next() else { panic!() };` is basically shorthand for: let x = match my_iter.next() { Some(val) => val, None => panic!() }; It’s destructuring the right hand side into the left, similar to doing fn get_coords(obj) -> Point2d { . . . } let Point2d { x, y } = get_coords(player); which creates two variables, x and y, whose values are the x and y fields of the Point2d returned by get_coords(). (1/2)

Replies (1)

  • @andy_f@fosstodon.org 2026-02-07 20:27

    The fun part is you can use this shorthand in if statements: if let Some(val) = my_iter.next() { println!(“Next iter value: {val}”); } else { println!(“No more values"); } Which naturally implies it also works with while loops: while let Some(val) = my_iter.next() { println!("Value: {val}”); } (2/2)

    Open ##3006381