Lokathor/bytemuck

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

Feature request: Casting owned slices or vec, I.e. Box<[u64]> to Box<[u8]> or Vec to Vec

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)

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

bytemuck::allocation::BoxBytes might fit your use-case, however it currently doesn't support casting to/from boxed slices, only boxed Sized types.

Thanks!