From: Alice Ryhl <aliceryhl@google.com>
To: lina@asahilina.net
Cc: alex.gaynor@gmail.com, benno.lossin@proton.me,
bjorn3_gh@protonmail.com, boqun.feng@gmail.com, gary@garyguo.net,
linux-kernel@vger.kernel.org, ojeda@kernel.org,
rust-for-linux@vger.kernel.org, wedsonaf@gmail.com
Subject: Re: [PATCH] rust: init: Implement Zeroable::zeroed()
Date: Fri, 14 Jul 2023 09:44:07 +0000 [thread overview]
Message-ID: <20230714094407.2188895-1-aliceryhl@google.com> (raw)
In-Reply-To: <20230714-zeroed-v1-1-494d6820d61b@asahilina.net>
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
next prev parent reply other threads:[~2023-07-14 9:44 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-14 9:17 [PATCH] rust: init: Implement Zeroable::zeroed() Asahi Lina
2023-07-14 9:44 ` Alice Ryhl [this message]
2023-07-15 9:58 ` Benno Lossin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230714094407.2188895-1-aliceryhl@google.com \
--to=aliceryhl@google.com \
--cc=alex.gaynor@gmail.com \
--cc=benno.lossin@proton.me \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=gary@garyguo.net \
--cc=lina@asahilina.net \
--cc=linux-kernel@vger.kernel.org \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=wedsonaf@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).