Macro transmute
macro_rules! transmute {
(#![allow(shrink)] $e:expr) => { ... };
($e:expr) => { ... };
}
Safely transmutes a value of one type to a value of another type of the same size.
This macro behaves like an invocation of this function:
const fn transmute<Src, Dst>(src: Src) -> Dst
where
Src: IntoBytes,
Dst: FromBytes,
size_of::<Src>() == size_of::<Dst>(),
{
# /*
...
# */
}
However, unlike a function, this macro can only be invoked when the types of
Src and Dst are completely concrete. The types Src and Dst are
inferred from the calling context; they cannot be explicitly specified in
the macro invocation.
Note that the Src produced by the expression $e will not be dropped.
Semantically, its bits will be copied into a new value of type Dst, the
original Src will be forgotten, and the value of type Dst will be
returned.
#![allow(shrink)]
If #![allow(shrink)] is provided, transmute! additionally supports
transmutations that shrink the size of the value; e.g.:
# use transmute;
let u: u32 = transmute!;
assert_eq!;
Examples
# use transmute;
let one_dimensional: = ;
let two_dimensional: = transmute!;
assert_eq!;
Use in const contexts
This macro can be invoked in const contexts.