rust: kernel: add `drop_contents` to `BoxExt`
authorBenno Lossin <benno.lossin@proton.me>
Mon, 19 Aug 2024 11:24:35 +0000 (11:24 +0000)
committerMiguel Ojeda <ojeda@kernel.org>
Wed, 21 Aug 2024 22:16:06 +0000 (00:16 +0200)
commit01db99b272318da75a1aa5a81f75adb9d32f676e
tree28406b1298bafefab366598dd182cfebe38d9f74
parent76501d19c6af43054492420ae53a9bd2d4de50b3
rust: kernel: add `drop_contents` to `BoxExt`

Sometimes (see [1]) it is necessary to drop the value inside of a
`Box<T>`, but retain the allocation. For example to reuse the allocation
in the future.

Introduce a new function `drop_contents` that turns a `Box<T>` into
`Box<MaybeUninit<T>>` by dropping the value.

Link: https://lore.kernel.org/rust-for-linux/20240418-b4-rbtree-v3-5-323e134390ce@google.com/
Signed-off-by: Benno Lossin <benno.lossin@proton.me>
Reviewed-by: Boqun Feng <boqun.feng@gmail.com>
Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Link: https://lore.kernel.org/r/20240819112415.99810-1-benno.lossin@proton.me
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
rust/kernel/alloc/box_ext.rs