Messages in this thread | | | Date | Fri, 14 Jul 2023 09:44:07 +0000 | Subject | Re: [PATCH] rust: init: Implement Zeroable::zeroed() | From | Alice Ryhl <> |
| |
Asahi Lina <lina@asahilina.net> writes: > +pub unsafe trait Zeroable: core::marker::Sized { > + /// Create a new zeroed T. > + /// > + /// Directly returns a zeroed T, analogous to Default::default(). > + fn zeroed() -> Self { > + unsafe { core::mem::zeroed() } > + } > +}
I don't think this trait needs to require `Sized`. How about the following alternate implementation?
pub unsafe trait Zeroable { /// Create a new zeroed T. /// /// Directly returns a zeroed T, analogous to Default::default(). fn zeroed() -> Self where Self: core::marker::Sized, { unsafe { core::mem::zeroed() } } }
Then types like [T] can also implement Zeroable when T does.
If you make the above change, then you may add my Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Alice
| |