Function safe_transmute::base::transmute_many_mut[][src]

pub unsafe fn transmute_many_mut<T, G: Guard>(
    bytes: &mut [u8]
) -> Result<&mut [T], Error<'_, u8, T>>
Expand description

View a mutable byte slice as a slice of an arbitrary type.

The required byte length of the slice depends on the chosen boundary guard. Please see the Guard API.

Safety

  • This function does not perform memory alignment checks. The beginning of the slice data must be properly aligned for accessing vlues of type T.
  • The byte data needs to correspond to a valid contiguous sequence of T values. Types T with a Drop implementation are unlikely to be safe in this regard.

Failure to fulfill any of the requirements above may result in undefined behavior.

Errors

An error is returned if the data does not comply with the policies of the given guard G.

Examples

// Little-endian
unsafe {
    assert_eq!(
        transmute_many_mut::<u16, SingleManyGuard>(&mut [0xFF, 0x01, 0x00, 0x02])?,
        &mut [0x01FF, 0x0200]
    );
}