-
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
Provide the ability to zero padding bytes and return &[u8]
#494
Comments
EDIT: We've decided to require I just realized that |
I suspect default-repr enums are going to render this strategy a non-starter, since we cannot reason about the size of their discriminants. Given that, do we still want to proceed with #1223? |
Discussed offline. Given this concern, and given the likelihood of |
Progress
KnownLayout
to require that fields implementKnownLayout
toofreeze
intrinsic (RFC 3605) will land and stabilize soon enough that we can rely on it instead; relaxKnownLayout
to not be recursive (and watch out for #1162)KnownLayout
requirement to implement this designDetails
Issues like this one demonstrate that it is sometimes useful to access the bytes of a type which cannot implement
AsBytes
. In these cases, it should be sound to:&[u8]
We would need to teach
KnownLayout
to be able to zero padding, e.g.:The only requirement for a type supporting this operation is that we know where its padding bytes are. The public API for this type could be in
KnownLayout
.As of this writing,
KnownLayout
does not require that a type's fields also beKnownLayout
. We are planning to add that requirement in order to support this design.Open questions
&T
(which we can't modify) into a buffer while initializing any padding bytes in the destination like musli-zerocopy does? See this discussion.fn zero_padding_and_get_bytes(&mut self) -> &[u8]
doesn't allow the type system to "remember" that a value has had its padding zeroed. Perhaps we could introduce a witness type and introduce a method like:fn zero_padding(&mut self) -> &mut AsBytesWitness<Self>
AsBytesWitness
would provide field projection into any field, but would only provide direct mutable access to fields which areAsBytes
(as writing to these fields cannot introduce uninitialized bytes)Related & prior art
freeze
intrinsic and related library functions rust-lang/rfcs#3605The text was updated successfully, but these errors were encountered: