-
Notifications
You must be signed in to change notification settings - Fork 107
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 &Initialized<T>
#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 |
&[u8]
&Initialized<T>
Note: We likely won't do this. See the conversation below for the full context, but TL;DR: We'd need for any
KnownLayout
type to require that all of its fields also implementKnownLayout
, which we don't currently require. We expect that thefreeze
language feature will land soon enough that it's not worth worseningKnownLayout
's UX to support this use case.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:&Initialized<T>
whereInitialized: IntoBytes
even whenT: !IntoBytes
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.Related & prior art
freeze
intrinsic and related library functions rust-lang/rfcs#3605The text was updated successfully, but these errors were encountered: