Latest Tech News

Stay updated with the latest in technology, AI, cybersecurity, and more

Filtered by: handle_b Clear Filter

Partially Matching Zig Enums

Partially Matching Zig Enums A short post about a neat little Zig idiom. Consider your average {sum type, variant, tagged union, enum, alt}: enum U { A ( i32 ), B ( i32 ), C, } Usually, you handle it like this: match u { U:: A (_) => handle_a (), U:: B (_) => handle_b (), U::C => handle_c (), } But once in a while, there’s common handling code you want to run for several variants. The most straightforward way is to duplicate: match u { U:: A (_) => { handle_ab (); handle_a (); } U:: B (_)