Function must_cast_mut
pub fn must_cast_mut<A, B>(a: &mut A) -> &mut B
Available on crate feature
dep_bytemuck
only.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);