bytemuck

Function must_cast_mut

Source
pub fn must_cast_mut<A: NoUninit + AnyBitPattern, B: NoUninit + AnyBitPattern>(
    a: &mut A,
) -> &mut B
Expand description

Convert a &mut A into &mut B if infalliable, or fail to compile.

As must_cast_ref, but mut.

§Examples

let mut i = 12_u16;
// compiles:
let bytes: &mut [u8; 2] = bytemuck::must_cast_mut(&mut i);
// fails to compile (alignment requirements increased):
let i : &mut u16 = bytemuck::must_cast_mut(bytes);
// fails to compile (size mismatch):
let bytes : &mut [u8; 3] = bytemuck::must_cast_mut(&mut i);