Lokathor/bytemuck

bytes_of_mut cannot be used with Vec<u32>

Closed this issue · 1 comments

I'm trying to use bytes_of_mut to get &mut Vec<u8> from Vec<u32>, but it seems not supporting that:

error[E0277]: the trait bound `std::vec::Vec<u32>: bytemuck::pod::Pod` is not satisfied
<snip>
    |
72  |         let vec_u8 = bytemuck::bytes_of_mut(&mut vec_u32);
    |                                               ^^^^^^^^^^^ the trait `bytemuck::pod::Pod` is not implemented for `std::vec::Vec<u32>`

Is there a plan to support that?

You can cast the slice of the vec's data from &[u32] to &[u8], or with &mut:

let byte_slice: &[u8] = cast_slice(&vec[..]);

but you can't convert Vec<u32> into Vec<u8> because of the alignment change, it would mess with the realloc/free process.