Skip to content

Commit b4fecce

Browse files
author
Andreas Hindborg
committed
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>
1 parent 042b0c7 commit b4fecce

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

rust/kernel/alloc/kbox.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,12 @@ where
245245
Ok(Self::new(x, flags)?.into())
246246
}
247247

248+
/// Convert a [`Box<T,A>`] to a [`Pin<Box<T,A>>`]. If `T` does not implement
249+
/// [`Unpin`], then `x` will be pinned in memory and can't be moved.
250+
pub fn into_pin(this: Self) -> Pin<Self> {
251+
this.into()
252+
}
253+
248254
/// Forgets the contents (does not run the destructor), but keeps the allocation.
249255
fn forget_contents(this: Self) -> Box<MaybeUninit<T>, A> {
250256
let ptr = Self::into_raw(this);

0 commit comments

Comments
 (0)