Function safe_transmute::to_bytes::transmute_to_bytes_unchecked[][src]

pub unsafe fn transmute_to_bytes_unchecked<S>(from: &S) -> &[u8]

Transmute a single instance of an arbitrary type into a slice of its bytes.

Examples

An u32:

unsafe {
    // Little-endian
    assert_eq!(transmute_to_bytes_unchecked(&0x0123_4567),
               &[0x67, 0x45, 0x23, 0x01]);
}

An arbitrary type:

#[repr(C)]
struct Gene {
    x1: u8,
    x2: u8,
}

unsafe {
    assert_eq!(transmute_to_bytes_unchecked(&Gene {
                   x1: 0x42,
                   x2: 0x69,
               }),
               &[0x42, 0x69]);
}