diff options
author | 2025-03-08 11:04:43 +0000 | |
---|---|---|
committer | 2025-03-16 21:59:18 +0100 | |
commit | 5657c3a9faf6c1243cecc9314244c92bfcd1ecad (patch) | |
tree | 8999fc069ff6d4bc3d1910edbc375a997110756b /rust/pin-init/src | |
parent | rust: pin-init: move impl `Zeroable` for `Opaque` and `Option<KBox<T>>` into the kernel crate (diff) | |
download | wireguard-linux-5657c3a9faf6c1243cecc9314244c92bfcd1ecad.tar.xz wireguard-linux-5657c3a9faf6c1243cecc9314244c92bfcd1ecad.zip |
rust: add `ZeroableOption` and implement it instead of `Zeroable` for `Option<Box<T, A>>`
When making pin-init its own crate, `Zeroable` will no longer be defined
by the kernel crate and thus implementing it for `Option<Box<T, A>>` is
no longer possible due to the orphan rule.
For this reason introduce a new `ZeroableOption` trait that circumvents
this problem.
Signed-off-by: Benno Lossin <benno.lossin@proton.me>
Reviewed-by: Fiona Behrens <me@kloenk.dev>
Reviewed-by: Andreas Hindborg <a.hindborg@kernel.org>
Tested-by: Andreas Hindborg <a.hindborg@kernel.org>
Link: https://lore.kernel.org/r/20250308110339.2997091-11-benno.lossin@proton.me
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
Diffstat (limited to 'rust/pin-init/src')
-rw-r--r-- | rust/pin-init/src/lib.rs | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/rust/pin-init/src/lib.rs b/rust/pin-init/src/lib.rs index aad6486d33fc..ca6be982b522 100644 --- a/rust/pin-init/src/lib.rs +++ b/rust/pin-init/src/lib.rs @@ -1297,6 +1297,17 @@ pub unsafe trait PinnedDrop: __internal::HasPinData { /// ``` pub unsafe trait Zeroable {} +/// Marker trait for types that allow `Option<Self>` to be set to all zeroes in order to write +/// `None` to that location. +/// +/// # Safety +/// +/// The implementer needs to ensure that `unsafe impl Zeroable for Option<Self> {}` is sound. +pub unsafe trait ZeroableOption {} + +// SAFETY: by the safety requirement of `ZeroableOption`, this is valid. +unsafe impl<T: ZeroableOption> Zeroable for Option<T> {} + /// Create a new zeroed T. /// /// The returned initializer will write `0x00` to every byte of the given `slot`. |