Function bytemuck::must_cast_slice_mut
source · pub fn must_cast_slice_mut<A: NoUninit + AnyBitPattern, B: NoUninit + AnyBitPattern>(
a: &mut [A]
) -> &mut [B]
Expand description
Convert &mut [A]
into &mut [B]
(possibly with a change in length) if
infalliable, or fail to compile.
As must_cast_slice
, but &mut
.
§Examples
let mut indicies = [1, 2, 3];
let indicies: &mut [u16] = &mut indicies;
// compiles:
let bytes: &mut [u8] = bytemuck::must_cast_slice_mut(indicies);
let zsts: &mut [()] = &mut [(), (), ()];
// compiles:
let bytes: &mut [u8] = bytemuck::must_cast_slice_mut(zsts);
ⓘ
// fails to compile (bytes.len() might not be a multiple of 2):
let byte_pairs : &mut [[u8; 2]] = bytemuck::must_cast_slice_mut(bytes);
ⓘ
// fails to compile (alignment requirements increased):
let indicies : &mut [u16] = bytemuck::must_cast_slice_mut(byte_pairs);
ⓘ
let bytes: &mut [u8] = &mut [];
// fails to compile: (bytes.len() might not be 0)
let zsts: &mut [()] = bytemuck::must_cast_slice_mut(bytes);