pub trait VirtualReturn: Sized {
type Raw;
// Required method
fn from_raw(raw: Self::Raw) -> Self;
}Expand description
How a value comes back from a C++ virtual call, and what to declare the foreign function as returning to receive it safely.
A C++ function returning bool, uint8_t or a 16-bit integer sets only the
low part of EAX; the rest of the register is left as it was. The official
IVehicle::isOccupied() on Windows ORs two pointers into EAX and then
setne %al — true comes back as 0x????..01. Rust, told the function
returns bool, assumes the register holds exactly 0 or 1, and a bool with
any other bit pattern is undefined behaviour: a comparison may read the
whole register and answer wrongly, with nothing to show for it.
So narrow types are received as the full register (Raw) and narrowed in
Rust, where truncation is defined. Everything else comes back as it is.
Required Associated Types§
Required Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".