[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20230714094407.2188895-1-aliceryhl@google.com>
Date: Fri, 14 Jul 2023 09:44:07 +0000
From: Alice Ryhl <aliceryhl@...gle.com>
To: lina@...hilina.net
Cc: alex.gaynor@...il.com, benno.lossin@...ton.me,
bjorn3_gh@...tonmail.com, boqun.feng@...il.com, gary@...yguo.net,
linux-kernel@...r.kernel.org, ojeda@...nel.org,
rust-for-linux@...r.kernel.org, wedsonaf@...il.com
Subject: Re: [PATCH] rust: init: Implement Zeroable::zeroed()
Asahi Lina <lina@...hilina.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@...gle.com>
Alice
Powered by blists - more mailing lists