[][src]Function safe_transmute::guarded_transmute_to_bytes_pod_vec

pub fn guarded_transmute_to_bytes_pod_vec<T: PodTransmutable>(
    from: Vec<T>
) -> Vec<u8>

Transmute a vector of POD types into a vector of their bytes, using the same memory buffer as the former.

Examples

Some u16s:

assert_eq!(guarded_transmute_to_bytes_pod_vec(vec![0x0123u16, 0x4567u16]),
           vec![0x23, 0x01, 0x67, 0x45]);

An arbitrary type:

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

assert_eq!(guarded_transmute_to_bytes_pod_vec(vec![Gene {
                                                    x1: 0x42,
                                                    x2: 0x69,
                                                   },
                                                   Gene {
                                                    x1: 0x12,
                                                    x2: 0x48,
                                                   }]),
           vec![0x42, 0x69, 0x12, 0x48]);