diff options
author | 2025-05-23 16:50:58 +0200 | |
---|---|---|
committer | 2025-06-11 21:13:56 +0200 | |
commit | c47024ba198b01cab6bb6e3e5a69b73ed2f2aa16 (patch) | |
tree | 58bb931785c11e0b13c60f1e6ae8fe729a07f782 | |
parent | rust: pin-init: rename `zeroed` to `init_zeroed` (diff) | |
download | wireguard-linux-c47024ba198b01cab6bb6e3e5a69b73ed2f2aa16.tar.xz wireguard-linux-c47024ba198b01cab6bb6e3e5a69b73ed2f2aa16.zip |
rust: pin-init: add `Zeroable::init_zeroed`
The trait function delegates to the already existing `init_zeroed`
function that returns a zeroing initializer for `Self`.
The syntax `..Zeroable::init_zeroed()` is already used by the
initialization macros to initialize all fields that are not mentioned in
the initializer with zero. Therefore it is expected that the function
also exists on the trait.
Link: https://github.com/Rust-for-Linux/pin-init/pull/56/commits/a424a6c9af5a4418a8e5e986a3db26a4432e2f1a
Link: https://lore.kernel.org/all/20250523145125.523275-3-lossin@kernel.org
Signed-off-by: Benno Lossin <lossin@kernel.org>
-rw-r--r-- | rust/pin-init/src/lib.rs | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/rust/pin-init/src/lib.rs b/rust/pin-init/src/lib.rs index 2f7ca94451e6..ef7e5a1e1c48 100644 --- a/rust/pin-init/src/lib.rs +++ b/rust/pin-init/src/lib.rs @@ -1495,7 +1495,18 @@ pub unsafe trait PinnedDrop: __internal::HasPinData { /// ```rust,ignore /// let val: Self = unsafe { core::mem::zeroed() }; /// ``` -pub unsafe trait Zeroable {} +pub unsafe trait Zeroable { + /// Create a new zeroed `Self`. + /// + /// The returned initializer will write `0x00` to every byte of the given `slot`. + #[inline] + fn init_zeroed() -> impl Init<Self> + where + Self: Sized, + { + init_zeroed() + } +} /// Marker trait for types that allow `Option<Self>` to be set to all zeroes in order to write /// `None` to that location. |