-
-
Notifications
You must be signed in to change notification settings - Fork 80
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
Getting allocated bytes (Box/Rc/Arc) out of Box<T> #167
Comments
Wouldn't this be unsound? When it comes to deallocation, |
Hmm, good point, I suppose some custom allocator might potentially care about alignment. Ugh... |
I suppose it could be allowed at least for structs where alignment == 1, similarly to what bytemuck already requires for |
At that point, wouldn't |
You can do this with a helper function (unsafely on stable, safely on nightly with
If you know the size of the type statically, then yeah you can |
Yes, if it supported unsized types like |
Oh yeah, sure, I know how to achieve it with unsafe code, when I said "I couldn't find a way" I meant specifically using bytemuck's safe APIs. |
Having a general sized-or-unsized to sized-or-unsized seems tricky to get right, But specifically a sized box into a byte slice box seems doable. Mostly, the crate is kinda light on box stuff because i don't use boxes much so i never thought about it too deeply. |
When working with allocated types, I often wish for a function like
bytemuck::bytes_of
but for heap types.For example, if I have a compatible
Box<Metadata>
, I should be able to receive a zero-costBox<[u8]>
and so on.For now, the only casts available are either between sized Boxes or between
Vec
s of different types but I couldn't find a way to go fromBox<T>
toVec<u8>
or anything similar.The text was updated successfully, but these errors were encountered: