Function safe_transmute::trivial::transmute_trivial_vec[][src]

pub unsafe fn transmute_trivial_vec<S: TriviallyTransmutable, T: TriviallyTransmutable>(
    vec: Vec<S>
) -> Vec<T>

Transform a vector into a vector of another element type.

The vector’s allocated byte buffer (if already allocated) will be reused.

Safety

Vector transmutations are exceptionally dangerous because of the constraints imposed by Vec::from_raw_parts().

Unless all of the following requirements are fulfilled, this operation may result in undefined behavior.

Examples

unsafe {
    assert_eq!(
        transmute_trivial_vec::<u8, i8>(vec![0x00, 0x01, 0x00, 0x02]),
        vec![0x00, 0x01, 0x00, 0x02]
    );
}