mirror of
https://github.com/torvalds/linux.git
synced 2025-12-07 20:06:24 +00:00
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>
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user