Function safe_transmute::to_bytes::transmute_to_bytes_vec

source ·
pub fn transmute_to_bytes_vec<S: TriviallyTransmutable>(
    from: Vec<S>
) -> Result<Vec<u8>, Error<'static, S, u8>>
Expand description

Transmute a vector of elements of an arbitrary type into a vector of their bytes, using the same memory buffer as the former.

This is equivalent to calling full::transmute_vec() where the target type is u8.

§Errors

An error is returned if the minimum memory alignment requirements are not the same between S and u8:

std::mem::align_of::<S>() != 1

The only truly safe way of doing this is to create a transmuted slice view of the vector or make a copy anyway.