Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bytes_of_mut cannot be used with Vec<u32> #40

Closed
keepsimple1 opened this issue Sep 11, 2020 · 1 comment
Closed

bytes_of_mut cannot be used with Vec<u32> #40

keepsimple1 opened this issue Sep 11, 2020 · 1 comment

Comments

@keepsimple1
Copy link

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?

@Lokathor
Copy link
Owner

Lokathor commented Sep 11, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants