]> www.infradead.org Git - users/dwmw2/linux.git/commit
rust: alloc: implement `IntoIterator` for `Vec`
authorDanilo Krummrich <dakr@kernel.org>
Fri, 4 Oct 2024 15:41:21 +0000 (17:41 +0200)
committerMiguel Ojeda <ojeda@kernel.org>
Tue, 15 Oct 2024 21:10:32 +0000 (23:10 +0200)
commit1d1d223aa3b37c34271aefc2706340d0843bfcb2
tree9846f4ed7c0058e53ec1b5d785385e1a11a35dd2
parent2aac4cd7dae3d7bb0e0ddec2561b2ee4cbe6c8f6
rust: alloc: implement `IntoIterator` for `Vec`

Implement `IntoIterator` for `Vec`, `Vec`'s `IntoIter` type, as well as
`Iterator` for `IntoIter`.

`Vec::into_iter` disassembles the `Vec` into its raw parts; additionally,
`IntoIter` keeps track of a separate pointer, which is incremented
correspondingly as the iterator advances, while the length, or the count
of elements, is decremented.

This also means that `IntoIter` takes the ownership of the backing
buffer and is responsible to drop the remaining elements and free the
backing buffer, if it's dropped.

Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Reviewed-by: Benno Lossin <benno.lossin@proton.me>
Reviewed-by: Gary Guo <gary@garyguo.net>
Signed-off-by: Danilo Krummrich <dakr@kernel.org>
Link: https://lore.kernel.org/r/20241004154149.93856-18-dakr@kernel.org
[ Fixed typos. - Miguel ]
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
rust/kernel/alloc.rs
rust/kernel/alloc/kvec.rs