You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Also TryFromBytes fields? Safe field accessor is still safe, but now fallible
How do we tell the attribute which fields are only TryFromBytes?
Should be able to codegen most of this based on a macro or proc macro attribute
Details
A macro or proc macro attribute that permits you to write a union. It is assumed that all fields are IntoBytes. It is assumed that all fields are FromBytes unless explicitly annotated as TryFromBytes.
#[zerocopy(union)]unionFoo{// No annotation => assumes this is FromBytesa:A,#[zerocopy(TryFromBytes)]b:B,}
This desugars into a [u8; N] (wrapped in a type which guarantees the appropriate alignment) which provides safe accessor methods, e.g.:
The internals could be represented, for example, as:
// This could live in `zerocopy::util::macro_util`unionUnionInner<T,Rest>{t:T,rest:Rest,}// Generated by the proc macro attribute#[repr(transparent)]structFoo(AlignedBytes<UnionInner<A,UnionInner<B,C>>>);
The text was updated successfully, but these errors were encountered:
Credit to @kupiakos for this idea
Requirements
FromBytes
/IntoBytes
TryFromBytes
fields? Safe field accessor is still safe, but now fallibleTryFromBytes
?Details
A macro or proc macro attribute that permits you to write a union. It is assumed that all fields are
IntoBytes
. It is assumed that all fields areFromBytes
unless explicitly annotated asTryFromBytes
.This desugars into a
[u8; N]
(wrapped in a type which guarantees the appropriate alignment) which provides safe accessor methods, e.g.:The internals could be represented, for example, as:
The text was updated successfully, but these errors were encountered: