I can't remember the name for this type of enum so I'll just write some example code:
use std::num::NonZeroU16;
enum SuccessOrError {
Success,
Error(NonZeroU16)
}
Which is the equivalent of Result<(), NonZeroU16>
. In Rust this will be represented by a single u16 but it produces a warning for FFI because the memory layout should be explicitly stated. However if I use repr
to set the layout to either u16
or C
it could use anywhere from 4 to 8 bytes instead of simply 2.
Can I explicitly state I want the compact layout? Or do I have to manually convert to/from a u16 for FFI?