Skip to content

Commit 2cafa7d

Browse files
hoshinolinajannau
authored andcommitted
rust: init: Implement Zeroable::zeroed()
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>
1 parent 885da21 commit 2cafa7d

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

rust/kernel/init.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1368,7 +1368,14 @@ pub unsafe trait PinnedDrop: __internal::HasPinData {
13681368
/// ```rust,ignore
13691369
/// let val: Self = unsafe { core::mem::zeroed() };
13701370
/// ```
1371-
pub unsafe trait Zeroable {}
1371+
pub unsafe trait Zeroable: core::marker::Sized {
1372+
/// Create a new zeroed T.
1373+
///
1374+
/// Directly returns a zeroed T, analogous to Default::default().
1375+
fn zeroed() -> Self {
1376+
unsafe { core::mem::zeroed() }
1377+
}
1378+
}
13721379

13731380
/// Create a new zeroed T.
13741381
///

0 commit comments

Comments
 (0)