]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
rust: alloc: add `Box::into_pin`
authorAndreas Hindborg <a.hindborg@kernel.org>
Sun, 9 Mar 2025 15:19:00 +0000 (16:19 +0100)
committerAndreas Hindborg <a.hindborg@kernel.org>
Sat, 22 Mar 2025 11:08:54 +0000 (12:08 +0100)
Add an associated function to convert a `Box<T>` into a `Pin<Box<T>>`.

Acked-by: Danilo Krummrich <dakr@kernel.org>
Reviewed-by: Benno Lossin <benno.lossin@proton.me>
Reviewed-by: Lyude Paul <lyude@redhat.com>
Link: https://lore.kernel.org/r/20250309-hrtimer-v3-v6-12-rc2-v12-9-73586e2bd5f1@kernel.org
Signed-off-by: Andreas Hindborg <a.hindborg@kernel.org>
rust/kernel/alloc/kbox.rs

index cb4ebea3b07422ca0f402512b7c66d66fd212042..9da4a32e60bc3fdfe88e595a38ecb9e3454e083f 100644 (file)
@@ -245,6 +245,12 @@ where
         Ok(Self::new(x, flags)?.into())
     }
 
+    /// Convert a [`Box<T,A>`] to a [`Pin<Box<T,A>>`]. If `T` does not implement
+    /// [`Unpin`], then `x` will be pinned in memory and can't be moved.
+    pub fn into_pin(this: Self) -> Pin<Self> {
+        this.into()
+    }
+
     /// Forgets the contents (does not run the destructor), but keeps the allocation.
     fn forget_contents(this: Self) -> Box<MaybeUninit<T>, A> {
         let ptr = Self::into_raw(this);