Function safe_transmute::trivial::transmute_trivial_vec
source · pub unsafe fn transmute_trivial_vec<S: TriviallyTransmutable, T: TriviallyTransmutable>(
vec: Vec<S>
) -> Vec<T>
Expand description
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.
- The target type
T
must have the same size and minimum memory alignment requirements as the typeS
.
§Examples
unsafe {
assert_eq!(
transmute_trivial_vec::<u8, i8>(vec![0x00, 0x01, 0x00, 0x02]),
vec![0x00, 0x01, 0x00, 0x02]
);
}