rust: alloc: add Vec::drain_all
authorAlice Ryhl <aliceryhl@google.com>
Fri, 2 May 2025 13:19:32 +0000 (13:19 +0000)
committerDanilo Krummrich <dakr@kernel.org>
Wed, 7 May 2025 16:39:22 +0000 (18:39 +0200)
commit088bf14a886e1e746c961a862ebccbb76d7cbd4e
tree4d3bc92e782cc77eb92f52d43a9247c0b0e2b3de
parent9def0d0a2a1c62d7970f4ce5ad5557968c98f637
rust: alloc: add Vec::drain_all

This is like the stdlib method drain, except that it's hard-coded to use
the entire vector's range. Rust Binder uses it in the range allocator to
take ownership of everything in a vector in a case where reusing the
vector is desirable.

Implementing `DrainAll` in terms of `slice::IterMut` lets us reuse some
nice optimizations in core for the case where T is a ZST.

Signed-off-by: Alice Ryhl <aliceryhl@google.com>
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Reviewed-by: Benno Lossin <lossin@kernel.org>
Link: https://lore.kernel.org/r/20250502-vec-methods-v5-4-06d20ad9366f@google.com
Signed-off-by: Danilo Krummrich <dakr@kernel.org>
rust/kernel/alloc/kvec.rs