Re:Portable and Interoperable Async Rust
by c-cube on Wednesday December 08, 2021 @07:39AM
(#29484006)
Zig has tagged unions and the corresponding switch expressions, is that not equivalent?
[ Parent
| on HN ]
Re:Portable and Interoperable Async Rust
by skohan on Wednesday December 08, 2021 @08:01AM
(#29484181)
I was not aware of these, either it was added since I kicked the tires on Zig or I just wasn't aware of it, but yes it looks pretty good!
The one drawback I see is that it seems a bit verbose: i.e. the tag set itself has to be declared as a separate enum, and then the tags need to be repeated inside the union.
So it looks to be slightly bolted-on and unergonomic (similar to TypeScript's implementation) but I haven't worked with it so maybe I am missing something.