Skip to main content

cast_to_u32

Function cast_to_u32 

Source
pub fn cast_to_u32(bytes: &[u8]) -> Result<&[u32], BytecodeError>
Expand description

Cast a byte slice to a u32 slice for ShaderModuleCreateInfo.

Returns an error if bytes.len() is not a multiple of 4 or the pointer is not 4-byte aligned. Use include_bytes! or aligned allocators to ensure correctness.

ยงExamples

use vulkan_rust::cast_to_u32;

#[repr(align(4))]
struct Aligned([u8; 8]);
let spirv = Aligned([0x03, 0x02, 0x23, 0x07, 0, 0, 0, 0]);
let words = cast_to_u32(&spirv.0).expect("alignment error");
assert_eq!(words.len(), 2);