Trait safe_transmute::PodTransmutable
source · pub unsafe trait PodTransmutable: Copy { }
Expand description
Type that can be non-unsafe
ly transmuted into
In most cases this is a POD class or a trivially copyable class.
Marker trait for guarded_transmute_pod_*()
functions.
Warning: if you transmute into a floating-point type you will have a chance to create a signaling NaN,
which, while not illegal, can be unwieldy. Check out util::designalise_f{32,64}()
for a remedy.
Nota bene: guarded transmutation to bool
s is provided as separate functions, because they’re
restricted to being 0
or 1
, which means that an additional value check is required.
Safety
It is only safe to implement PodTransmutable
for a type T
if it is safe for a slice of any arbitrary data
&[u8]
of length sizeof<T>()
to be transmute()
d
to a unit-length &[T]
.
Consult the Transmutes section of the Nomicon for more details.