[−][src]Trait safe_transmute::pod::PodTransmutable
Type that can be non-unsafe
ly transmuted into
A type T
implementing this trait means that any arbitrary slice of bytes
of length size_of::<T>()
can be safely interpreted as a value of that
type in all circumstances. In most cases this is a
POD class or a
trivially copyable class.
This serves as a marker trait for all functions in this module.
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: bool
is not PodTransmutable
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]
, without any other conversion operation being required.
Consult the Transmutes section of the Nomicon for more details.