Function safe_transmute::guarded_transmute_pod_vec
source · Expand description
Trasform a byte vector into a vector of POD.
The resulting vec will reuse the allocated byte buffer when possible, and should have at least enough bytes to fill a single instance of a type. Extraneous data is ignored.
Examples
// Little-endian
assert_eq!(guarded_transmute_pod_vec::<u16>(vec![0x00, 0x01, 0x00, 0x02])?,
vec![0x0100, 0x0200]);
assert_eq!(guarded_transmute_pod_vec::<u32>(vec![0x04, 0x00, 0x00, 0x00, 0xED])?,
vec![0x00000004]);
assert!(guarded_transmute_pod_vec::<i16>(vec![0xED]).is_err());