]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
rust: alloc: implement `IntoIterator` for `Vec`
authorDanilo Krummrich <dakr@kernel.org>
Fri, 7 Mar 2025 22:49:43 +0000 (23:49 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 13 Mar 2025 12:01:45 +0000 (13:01 +0100)
commit94091ef3d5aaaf34f429cd1ba95b40303e45494b
treea2f1832a7a087f4cd96aa745810a28c4b91d933b
parent0ca66a44e241a8ac998876ebb4c460155e517d58
rust: alloc: implement `IntoIterator` for `Vec`

commit 1d1d223aa3b37c34271aefc2706340d0843bfcb2 upstream.

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>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
rust/kernel/alloc.rs
rust/kernel/alloc/kvec.rs