3 ms·
In Rust's case, union types should only be used for FFI with a C ABI. As for C, it is a sharp blade on its own.
by pjmlp 7mo ago
In Rust's case, union types should only be used for FFI with a C ABI.
As for C, it is a sharp blade on its own.
- tialaramex 7mo agoI do not agree. MaybeUninit<T> is without any doubt more valuable than the C FFI use I can't even think of any prominent C FFI problems where I'd reach for the union's C representation. Too many languages can't handle that so it seems less useful at an FFI edge.
- pjmlp 7mo agoOS APIs for one, at least there are some Win32 calls that take unions if I remember correctly. One of the reasons .NET had Managed C++, replaced by C++/CLI (nowadays C++20 compliant, minus modules), is exactly that P/Invoke (and RCW/CCW) cannot represent everything. Which they don't want to expose on .NET type system directly.