Module safe_transmute::trivial

source ·
Expand description

Transmutation of trivial objects

Functions in this module are guarded from out-of-bounds memory access and from unsafe transmutation target types through the use of the TriviallyTransmutable) trait.

If a certain type can be safely constructed out of any byte combination, then it may implement this trait. This is the case for primitive integer types (e.g. i32, u32, i64), arrays of other trivially transmutable types, and repr(C) structs composed of trivially transmutable values.

However, they are still not entirely safe because the source data may not be correctly aligned for reading and writing a value of the target type. The effects of this range from less performance (e.g. x86) to trapping or address flooring (e.g. ARM), but this is undefined behavior nonetheless.

Traits§

Functions§