Converting [[f32; 4]; 4] to [f32; 16]

Is the layout of [[f32; 4]; 4] and [f32; 16] compatible?

If not, why not, and if so, how do we make the conversion?

Yes, layout is compatible, but you'll have to use a bit of unsafe to do the conversion:

fn convert(a: [[f32; 4]; 4]) -> [f32; 16] {
    unsafe { std::mem::transmute(a) }
}
3 Likes