Skip to content

Commit e8f05cf

Browse files
committed
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 <[email protected]>
1 parent b9e568e commit e8f05cf

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
@@ -1584,7 +1584,14 @@ pub unsafe trait PinnedDrop: __internal::HasPinData {
15841584
/// ```rust,ignore
15851585
/// let val: Self = unsafe { core::mem::zeroed() };
15861586
/// ```
1587-
pub unsafe trait Zeroable {}
1587+
pub unsafe trait Zeroable: core::marker::Sized {
1588+
/// Create a new zeroed T.
1589+
///
1590+
/// Directly returns a zeroed T, analogous to Default::default().
1591+
fn zeroed() -> Self {
1592+
unsafe { core::mem::zeroed() }
1593+
}
1594+
}
15881595

15891596
/// Create a new zeroed T.
15901597
///

0 commit comments

Comments
 (0)