3 ms·
I think they meant that the use case corresponds closely, not the representation. Generally C unions get used the same place Rust unions would in a rust program
by Manishearth 10y ago
I think they meant that the use case corresponds closely, not the representation. Generally C unions get used the same place Rust unions would in a rust program (not vice versa though), unless they're being used for type punning, which is pretty rare anyway.
- awinter-py 10y agoI meant if you have a large program where many types are C unions like: struct TaggedUnion { enum {T1, T2} type_id; union {type1 t1; type2 t2;} u; } If the goal is to translate automatically to a rust enum declaration, that will be (a) possible to do with an automatic tool and (b) will give enhanced safety because it will force the type to be checked everywhere these values are used.