Function core::mem::transmute_copy [] [src]

pub unsafe fn transmute_copy<T, U>(src: &T) -> U

Interprets src`srcas` as &U`&U, and then reads`, and then reads src`src` without moving the contained value.

This function will unsafely assume the pointer src`srcis valid for` is valid for sizeof(U)`sizeof(U)bytes by transmuting` bytes by transmuting &T`&Tto` to &U`&Uand then reading the` and then reading the &U`&U. It will also unsafely create a copy of the contained value instead of moving out of`. It will also unsafely create a copy of the contained value instead of moving out of src`src`.

It is not a compile-time error if T`Tand` and U`Uhave different sizes, but it is highly encouraged to only invoke this function where` have different sizes, but it is highly encouraged to only invoke this function where T`Tand` and U`Uhave the same size. This function triggers undefined behavior if` have the same size. This function triggers undefined behavior if U`Uis larger than` is larger than T`T`.

Examples

fn main() { use std::mem; let one = unsafe { mem::transmute_copy(&1) }; assert_eq!(1, one); }
use std::mem;

let one = unsafe { mem::transmute_copy(&1) };

assert_eq!(1, one);