flamingo_pinyata@sopuli.xyz to Programmer Humor@programming.dev · 2 days agoYou can pry pattern matching from my cold dead handssopuli.xyzimagemessage-square214linkfedilinkarrow-up1509arrow-down117
arrow-up1492arrow-down1imageYou can pry pattern matching from my cold dead handssopuli.xyzflamingo_pinyata@sopuli.xyz to Programmer Humor@programming.dev · 2 days agomessage-square214linkfedilink
minus-squareSorryQuick@lemmy.calinkfedilinkarrow-up6·edit-222 hours agoYou can also use let else. let (Some(count\_str), Some(item)) = (it.next(), it.next()) else { panic!("Can't segment count item pair: '{s}'"); }; But really it’s the exact same as other languages, it just forces you to handle it better. C-based languages will return 0/null/-1 and you’ll have to check all 3 of those because they might not mean the same thing. How is that better?
You can also use let else.
let (Some(count\_str), Some(item)) = (it.next(), it.next()) else { panic!("Can't segment count item pair: '{s}'"); };But really it’s the exact same as other languages, it just forces you to handle it better. C-based languages will return 0/null/-1 and you’ll have to check all 3 of those because they might not mean the same thing. How is that better?