Loading RustViz Engine...
Safely cast between byte slices and integer arrays validating memory alignment.
This problem is currently in blueprint template mode. Once the concept foundation is finalized, live in-browser WebAssembly compilation and test assertion runners will be enabled here.
pub fn bytes_to_u32_slice(bytes: &[u8]) -> Option<&[u32]> {
if bytes.len() % 4 != 0 { return None; }
if (bytes.as_ptr() as usize) % std::mem::align_of::<u32>() != 0 { return None; }
unsafe {
Some(std::slice::from_raw_parts(bytes.as_ptr() as *const u32, bytes.len() / 4))
}
}