Feature request: Casting owned slices or vec, I.e. Box<[u64]> to Box<[u8]> or Vec<u64> to Vec<u8>
forrestli74 opened this issue · 4 comments
forrestli74 commented
Feature request: Casting owned slices or vec, I.e. Box<[u64]> to Box<[u8]> or Vec to Vec
zachs18 commented
You can't go directly from Box<[u64]>
to Box<[u8]>
due to allocation alognment requirements, but you can use cast_slice
and then slice::to_vec
to get an owned vec in a new allocation (and then Vec::into_boxed_slice
if needed)
forrestli74 commented
I was really looking for a solution with no copy or new allocation. I didn't know this was impossible. Any suggestions for future reading? Thanks
zachs18 commented
bytemuck::allocation::BoxBytes
might fit your use-case, however it currently doesn't support casting to/from boxed slices, only boxed Sized types.
forrestli74 commented
Thanks!