Is there a safer way to use unions to convert between integer and floating-point numbers?
问题 I´m writing a VM in Rust and I have a C and C++ background. I need union-like functionality because on the VM stack I can either store an int or a float . In C I had a union: union stack_record_t { int i; float f; }; I can use the record as int or as float with zero runtime overhead. I have a static bytecode analyzer which will find type errors before the bytecode executes, so I don't have to store a flag alongside the record. I don´t know if it is a good idea to use unions in Rust because