[−][src]Function safe_transmute::transmute_vec_permissive
pub fn transmute_vec_permissive<T: TriviallyTransmutable>(
bytes: Vec<u8>
) -> Result<Vec<T>, Error>
Transform a byte vector into a vector of values.
The vector's allocated byte buffer will be reused when possible, and have as many instances of a type as will fit, rounded down. Extraneous data is ignored.
Errors
An error is returned in one of the following situations:
- The data does not have a memory alignment compatible with
T
. You will have to make a copy anyway, or modify how the data was originally made.
Examples
// Little-endian assert_eq!(transmute_vec_permissive::<u16>(vec![0x00, 0x01, 0x00, 0x02]), Ok(vec![0x0100, 0x0200])); assert_eq!(transmute_vec_permissive::<u32>(vec![0x04, 0x00, 0x00, 0x00, 0xED]), Ok(vec![0x0000_0004])); assert_eq!(transmute_vec_permissive::<u16>(vec![0xED]), Ok(vec![]));