-
Notifications
You must be signed in to change notification settings - Fork 142
Description
This issue used to track FromZeroes, which has now been merged. However, support for #[derive(FromZeroes)] is incomplete - the rules implemented when deriving on an enum are equivalent to the rules for deriving FromBytes on an enum. Those rules are unnecessarily restrictive.
Now, this issue tracks:
- Figuring out what rules enums need to follow in order to be
FromZeroes - Modifying our derive to implement those rules
Old text
Add an unsafe marker trait called FromZeroes (or similar) which indicates that a type can be safely constructed from all 0 bytes. Add a custom derive to zerocopy-derive for this trait.
I would expect the API to look something like this:
unsafe trait FromZeroes {
#[doc(hidden)]
fn only_derive_is_allowed_to_implement_this_trait() where Self: Sized;
fn zero(&mut self);
// These would all be moved from `FromBytes`.
fn new_zeroed() -> Self where Self: Sized { ... }
#[cfg(feature = "alloc")]
fn new_box_zeroed() -> Box<Self> where Self: Sized { ... }
#[cfg(feature = "alloc")]
fn new_box_slice_zeroed() -> Box<Self> where Self: Sized { ... }
// If we also implement `Zeroed` (#31):
fn read_from_zeroed<B: ByteSlice>(bytes: Zeroed<B>) -> Option<Self> where Self: Sized { ... }
fn read_from_zeroed_prefix<B: ByteSlice>(bytes: Zeroed<B>) -> Option<Self> where Self: Sized { ... }
fn read_from_zeroed_suffix<B: ByteSlice>(bytes: Zeroed<B>) -> Option<Self> where Self: Sized { ... }
}
// `FromBytes` would gain a `FromZeroes` bound.
unsafe trait FromBytes: FromZeroes { ... }Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels