News for hackers. Stuff that matters.
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?
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.

Re:Portable and Interoperable Async Rust by nyberg on Friday December 10, 2021 @05:26PM (#29516201)
You can use union(enum) to avoid having to write a separate enum definition for tags and std.meta.FieldEnum() exists should you also want to derive an enum from the union later on.