diff options
author | Andreas Hindborg <a.hindborg@kernel.org> | 2025-03-09 16:19:00 +0100 |
---|---|---|
committer | Andreas Hindborg <a.hindborg@kernel.org> | 2025-03-22 12:08:54 +0100 |
commit | b4fecceee29e2a6453ac746e70c16fe7f70babf9 (patch) | |
tree | 1f09cba5dd32a4369c55572c439b4c88c673b8b5 | |
parent | 042b0c7947d39aeac34b35fb89034ca1345f1fc3 (diff) |
rust: alloc: add `Box::into_pin`
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>
-rw-r--r-- | rust/kernel/alloc/kbox.rs | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/rust/kernel/alloc/kbox.rs b/rust/kernel/alloc/kbox.rs index cb4ebea3b074..9da4a32e60bc 100644 --- a/rust/kernel/alloc/kbox.rs +++ b/rust/kernel/alloc/kbox.rs @@ -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); |