rust-for-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] rust: init: Implement Zeroable::zeroed()
@ 2023-07-14  9:17 Asahi Lina
  2023-07-14  9:44 ` Alice Ryhl
  2023-07-15  9:58 ` Benno Lossin
  0 siblings, 2 replies; 3+ messages in thread
From: Asahi Lina @ 2023-07-14  9:17 UTC (permalink / raw)
  To: Miguel Ojeda, Alex Gaynor, Wedson Almeida Filho, Boqun Feng,
	Gary Guo, Björn Roy Baron, Benno Lossin
  Cc: rust-for-linux, linux-kernel, Asahi Lina

By analogy to Default::default(), this just returns the zeroed
representation of the type directly. init::zeroed() is the version that
returns an initializer.

Signed-off-by: Asahi Lina <lina@asahilina.net>
---
 rust/kernel/init.rs | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/rust/kernel/init.rs b/rust/kernel/init.rs
index b4332a4ec1f4..c300ce39ac10 100644
--- a/rust/kernel/init.rs
+++ b/rust/kernel/init.rs
@@ -1354,7 +1354,14 @@ pub unsafe trait PinnedDrop: __internal::HasPinData {
 /// ```rust,ignore
 /// let val: Self = unsafe { core::mem::zeroed() };
 /// ```
-pub unsafe trait Zeroable {}
+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() }
+    }
+}
 
 /// Create a new zeroed T.
 ///

---
base-commit: 06c2afb862f9da8dc5efa4b6076a0e48c3fbaaa5
change-id: 20230714-zeroed-dd05bc737f85

Thank you,
~~ Lina


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-07-15  9:58 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-14  9:17 [PATCH] rust: init: Implement Zeroable::zeroed() Asahi Lina
2023-07-14  9:44 ` Alice Ryhl
2023-07-15  9:58 ` Benno Lossin

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).