[][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:

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());