Impl Read for reference of u8 array

let vs_data = wgpu::read_spirv(include_bytes!("vertex.spirv")).unwrap();
let fs_data = wgpu::read_spirv(include_bytes!("fragment.spirv")).unwrap();

I wanted to read directly from the spirv file but,however I try get some sort of compiler error trying to do it. I tried putting it in BuffReader::new. But, still the same error. i.e.

let vs_data = wgpu::read_spirv(include_bytes!("vertex.spirv")).unwrap();
    |                                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::io::Read` is not implemented for `&[u8; 1096]`

I put .into(), but, that didn't also work. So, basically is there library that implements Read for this reference of u8 array. Or do I have to write an implementation for this?

Neither is the case. There is a Read implementation for slices. You just need to convert from &[u8; 1096] to &[u8] manually here since in the context of traits, the automatic coercion easily fails. Either by using as like in include_bytes!("filename") as &[u8] or creating a slice explicitly like &include_bytes!("filename")[..].


Thanks bro. I changed it to like this. Its working now.

let vs_data = wgpu::read_spirv(std::io::Cursor::new(include_bytes!("vertex.spirv") as &[u8])).unwrap();
let fs_data = wgpu::read_spirv(std::io::Cursor::new(include_bytes!("fragment.spirv") as &[u8])).unwrap();

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.