[−][src]Function safe_transmute::safe_transmute_vec
pub fn safe_transmute_vec<T: PodTransmutable, G: Guard>(
bytes: Vec<u8>
) -> Result<Vec<T>, Error>
Transform a byte vector into a vector of values.
The resulting vec will reuse the allocated byte buffer when successful.
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. - The data does not comply with the given memory guard strategy.
Examples
// Little-endian assert_eq!(safe_transmute_vec::<u16, SingleManyGuard>(vec![0x00, 0x01, 0x00, 0x02])?, vec![0x0100, 0x0200]); assert_eq!(safe_transmute_vec::<u32, SingleManyGuard>(vec![0x04, 0x00, 0x00, 0x00, 0xED])?, vec![0x0000_0004]); assert!(safe_transmute_vec::<i16, SingleManyGuard>(vec![0xED]).is_err());