mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-09-18 22:14:16 +00:00
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: a424a6c9af
Link: https://lore.kernel.org/all/20250523145125.523275-3-lossin@kernel.org
Signed-off-by: Benno Lossin <lossin@kernel.org>
This commit is contained in:
parent
101b7cf006
commit
c47024ba19
1 changed files with 12 additions and 1 deletions
|
@ -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.
|
||||
|
|
Loading…
Add table
Reference in a new issue