-
Notifications
You must be signed in to change notification settings - Fork 109
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
Features to support musli-zerocopy #523
Comments
@udoprog re: bytes to type conversion: You can usually accomplish this by constructing a |
Hi! I'll go through some of the major areas I've yet to find a solution for:
pub struct Padder<'a, T: ?Sized> {
ptr: *mut u8,
offset: usize,
_marker: PhantomData<&'a mut T>,
}
impl<'a, T: ?Sized> Padder<'a, T> {
pub(crate) fn new(ptr: *mut u8) -> Self {
Self {
ptr,
offset: 0,
_marker: PhantomData,
}
}
/* methods that derived structures uses to indicate which fields and discriminators are present */
}
trait UnsizedPaddable {
unsafe fn pad(&self, pad: &mut Padder<'_, Self>);
}
trait Paddable {
unsafe fn pad(&self, pad: &mut Padder<'_, Self>);
} That way, anything that can provide a mutable pointer can have padding bytes written to it, like a To use such an API, the caller is resonsible for ensuring that a buffer with capacity
Again, please advise if there's something about |
Does #5 address this use case?
I think I roughly understand what's going on here, but can you say more about how this API is used? We have #494 which it sounds like describes something similar, but I'm not sure if it'd fully cover your use case.
Yeah, we're feeling this pain too. I've submitted rust-lang/reference#1417, which should provide enough of a guarantee that you can build unsized type support on top of it (basically, you use
|
That is the same as my You can actually see how the proposed method in #494 could be implemented using |
"Well" as-in, the ability to pad something solely based on a |
Okay gotcha, thanks for clarifying! IIUC, the point is that you need to be able to take a I've updated #494 to mention this use case. |
See https://udoprog.github.io/rust/2023-10-19/musli-zerocopy.html and https://docs.rs/musli-zerocopy/latest/musli_zerocopy/.
Better ergonomics/discoverability for bytes-to-reference-type conversion (what is currently only supported by constructing aRef
and then converting to a reference)FromBytes
#526&Initialized<T>
#494TryFromBytes
- conditional conversion analogous toFromBytes
#5cc @udoprog
The text was updated successfully, but these errors were encountered: