pub trait ReprC {
// Provided method
unsafe fn repr_c_optimization_safe(_version: u32) -> IsReprC { ... }
}
Expand description
This trait describes whether a type is such that it can just be blitted. See method repr_c_optimization_safe.
Provided Methods§
sourceunsafe fn repr_c_optimization_safe(_version: u32) -> IsReprC
unsafe fn repr_c_optimization_safe(_version: u32) -> IsReprC
This method returns true if the optimization is allowed for the protocol version given as an argument. This may return true if and only if the given protocol version has a serialized format identical to the given protocol version.
This can return true for types which have an in-memory layout that is packed and therefore identical to the layout that savefile will use on disk. This means that types for which this trait is implemented can be serialized very quickly by just writing their raw bits to disc.
Rules to allow returning true:
- The type must be copy
- The type must not contain any padding (if there is padding, backward compatibility will fail, since in fallback mode regular savefile-deserialize will be used, and it will not use padding)
- The type must have a strictly deterministic memory layout (no field order randomization). This typically means repr(C)
- All the constituent types of the type must also implement
ReprC
(correctly).
Constructing an instance of ‘IsReprC’ with value ‘true’ is not safe. See documentation of ‘IsReprC’. The idea is that the ReprC-trait itself can still be safe to implement, it just won’t be possible to get hold of an instance of IsReprC(true). To make it impossible to just ‘steal’ such a value from some other thing implementign ‘ReprC’, this method is marked unsafe.
§SAFETY
The returned value must not be used, except by the Savefile-framework. It must not be be forwarded anywhere else.