[−][src]Module typic::transmute
Traits for safe and sound transmutation.
Three Types of Transmutation
Unsound Transmutation
The transmute
and transmute_copy
intrinsics
allow for the unsafe and unsound transmutation between any T
and U
.
These intrinsics are deeply unsafe. The Rust compiler will accept uses of
these intrinsics even when T
and U
do not have well-defined layouts.
Always use a safe transmutation method instead,
if possible. If you are unable to use a safe transmutation method,
you may be relying on undefined compiler behavior.
Sound Transmutation
The unsafe_transmute
function allows for the unsafe transmutation
between T
and U
, when merely transmuting from T
to U
will not cause
undefined behavior. For the key rules that govern when T
is soundly
convertible to U
, see When is a transmutation sound?.
This operation is unsafe
, as it will bypass any user-defined validity
restrictions that U
places on its fields and enforces with its
constructors and methods.
Always use a safe transmutation method instead, if possible. If you are unable to use a safe transmutation method, you may be violating library invariants.
Safe Transmutation
The TransmuteInto<U>
trait is implemented for a type T
if:
If you are unable to use TransmuteInto<U>
, you may be attempting a
transmutation that is relying unspecified behavior.
Modules
neglect | What static checks should Typic neglect? |
safe_transmutation | Guidance and tools for safe transmutation. |
unsafe_transmutation | Guidance and tools for sound transmutation. |
Traits
StableTransmuteInto | For ergonomics, until rust-lang/rust#27336 is resolved. |
TransmuteFrom | A safe and sound value-to-value conversion.
The reciprocal of |
TransmuteInto | A safe and sound value-to-value conversion.
The reciprocal of |
TransmuteOptions | Options for safe and unsafe transmutation. |
UnsafeTransmuteFrom | A sound value-to-value conversion.
The reciprocal of |
UnsafeTransmuteInto | A sound value-to-value conversion.
The reciprocal of |
UnsafeTransmuteOptions | Options for unsafe transmutation. |
Functions
safe_transmute | A safe and sound value-to-value conversion. |
unsafe_transmute⚠ | A sound value-to-value conversion. |