macro_rules! transmute { ($e:expr) => { ... }; }
Expand description
Safely transmutes a value of one type to a value of another type of the same size.
The expression $e
must have a concrete type, T
, which implements
AsBytes
. The transmute!
expression must also have a concrete type, U
(U
is inferred from the calling context), and U
must implement
FromBytes
.
Note that the T
produced by the expression $e
will not be dropped.
Semantically, its bits will be copied into a new value of type U
, the
original T
will be forgotten, and the value of type U
will be returned.
Examples
let one_dimensional: [u8; 8] = [0, 1, 2, 3, 4, 5, 6, 7];
let two_dimensional: [[u8; 4]; 2] = transmute!(one_dimensional);
assert_eq!(two_dimensional, [[0, 1, 2, 3], [4, 5, 6, 7]]);