rust: pin-init: move impl Zeroable for Opaque and Option<KBox<T>> into the kernel crate

In order to make pin-init a standalone crate, move kernel-specific code
directly into the kernel crate. Since `Opaque<T>` and `KBox<T>` are part
of the kernel, move their `Zeroable` implementation into the kernel
crate.

Signed-off-by: Benno Lossin <benno.lossin@proton.me>
Tested-by: Andreas Hindborg <a.hindborg@kernel.org>
Reviewed-by: Fiona Behrens <me@kloenk.dev>
Link: https://lore.kernel.org/r/20250308110339.2997091-10-benno.lossin@proton.me
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
This commit is contained in:
Benno Lossin
2025-03-08 11:04:38 +00:00
committed by Miguel Ojeda
parent 114ca41fe7
commit 9d29c682f0
3 changed files with 12 additions and 9 deletions

View File

@@ -2,7 +2,7 @@
//! Kernel types.
use crate::init::{self, PinInit};
use crate::init::{self, PinInit, Zeroable};
use core::{
cell::UnsafeCell,
marker::{PhantomData, PhantomPinned},
@@ -309,6 +309,9 @@ pub struct Opaque<T> {
_pin: PhantomPinned,
}
// SAFETY: `Opaque<T>` allows the inner value to be any bit pattern, including all zeros.
unsafe impl<T> Zeroable for Opaque<T> {}
impl<T> Opaque<T> {
/// Creates a new opaque value.
pub const fn new(value: T) -> Self {