[][src]Function safe_transmute::to_bytes::safe_transmute_one_to_bytes

pub fn safe_transmute_one_to_bytes<T: PodTransmutable>(from: &T) -> &[u8]

Transmute a single instance of a POD type into a slice of its bytes.

Examples

An u32:

assert_eq!(safe_transmute_one_to_bytes(&0x0123_4567),
           &[0x67, 0x45, 0x23, 0x01]);

An arbitrary type:

#[repr(C)]
#[derive(Clone, Copy)]
struct Gene {
    x1: u8,
    x2: u8,
}
unsafe impl PodTransmutable for Gene {}

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