From: Andreas Hindborg Date: Sun, 9 Mar 2025 15:19:00 +0000 (+0100) Subject: rust: alloc: add `Box::into_pin` X-Git-Tag: v6.15-rc1~93^2^2~4 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=b4fecceee29e2a6453ac746e70c16fe7f70babf9;p=thirdparty%2Fkernel%2Flinux.git rust: alloc: add `Box::into_pin` Add an associated function to convert a `Box` into a `Pin>`. Acked-by: Danilo Krummrich Reviewed-by: Benno Lossin Reviewed-by: Lyude Paul Link: https://lore.kernel.org/r/20250309-hrtimer-v3-v6-12-rc2-v12-9-73586e2bd5f1@kernel.org Signed-off-by: Andreas Hindborg --- diff --git a/rust/kernel/alloc/kbox.rs b/rust/kernel/alloc/kbox.rs index cb4ebea3b0742..9da4a32e60bc3 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`] to a [`Pin>`]. 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 { + this.into() + } + /// Forgets the contents (does not run the destructor), but keeps the allocation. fn forget_contents(this: Self) -> Box, A> { let ptr = Self::into_raw(this);