All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/5] Additional methods for Vec
@ 2025-03-20 13:52 Alice Ryhl
  2025-03-20 13:52 ` [PATCH 1/5] rust: alloc: add Vec::clear Alice Ryhl
                   ` (5 more replies)
  0 siblings, 6 replies; 16+ messages in thread
From: Alice Ryhl @ 2025-03-20 13:52 UTC (permalink / raw)
  To: Danilo Krummrich; +Cc: rust-for-linux, linux-kernel, Alice Ryhl

This adds various Vec methods. Some of them are needed by Rust Binder,
and others are needed in other places. Each commit explains where it is
needed.

I'm not sure what we concluded on the set_len / dec_len changes, so I
don't depend on that series for now.

This series is based on top of Vec::truncate from
https://lore.kernel.org/rust-for-linux/20250316111644.154602-1-andrewjballance@gmail.com/

Signed-off-by: Alice Ryhl <aliceryhl@google.com>
---
Alice Ryhl (5):
      rust: alloc: add Vec::clear
      rust: alloc: add Vec::pop
      rust: alloc: add Vec::push_within_capacity
      rust: alloc: add Vec::drain_all
      rust: alloc: add Vec::retain

 rust/kernel/alloc/kvec.rs | 147 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 147 insertions(+)
---
base-commit: a337a03281efc4553191b432d757d4c04884bf4c
change-id: 20250320-vec-methods-adfa41e55311

Best regards,
-- 
Alice Ryhl <aliceryhl@google.com>


^ permalink raw reply	[flat|nested] 16+ messages in thread
* Re: [PATCH 5/5] rust: alloc: add Vec::retain
@ 2025-03-20 22:21 Benno Lossin
  0 siblings, 0 replies; 16+ messages in thread
From: Benno Lossin @ 2025-03-20 22:21 UTC (permalink / raw)
  To: Alice Ryhl, Danilo Krummrich; +Cc: rust-for-linux, linux-kernel

On Thu Mar 20, 2025 at 2:53 PM CET, Alice Ryhl wrote:
> diff --git a/rust/kernel/alloc/kvec.rs b/rust/kernel/alloc/kvec.rs
> index 303198509885f5e24b74da5a92382b518de3e1c0..00dabea8ea6c8a742a7fc95954d8de58be124493 100644
> --- a/rust/kernel/alloc/kvec.rs
> +++ b/rust/kernel/alloc/kvec.rs
> @@ -588,6 +588,20 @@ pub fn drain_all(&mut self) -> DrainAll<'_, T> {
>              elements: self.spare_capacity_mut()[..len].iter_mut(),
>          }
>      }
> +
> +    /// Removes all elements that don't match the provided closure.

Can you also add an example here? Otherwise the code looks good.

---
Cheers,
Benno

> +    pub fn retain(&mut self, mut f: impl FnMut(&mut T) -> bool) {
> +        let mut num_kept = 0;
> +        let mut next_to_check = 0;
> +        while let Some(to_check) = self.get_mut(next_to_check) {
> +            if f(to_check) {
> +                self.swap(num_kept, next_to_check);
> +                num_kept += 1;
> +            }
> +            next_to_check += 1;
> +        }
> +        self.truncate(num_kept);
> +    }
>  }
>  
>  impl<T: Clone, A: Allocator> Vec<T, A> {



^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2025-04-22  9:48 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-20 13:52 [PATCH 0/5] Additional methods for Vec Alice Ryhl
2025-03-20 13:52 ` [PATCH 1/5] rust: alloc: add Vec::clear Alice Ryhl
2025-03-20 22:01   ` Benno Lossin
2025-03-20 22:04   ` Tamir Duberstein
2025-03-20 13:52 ` [PATCH 2/5] rust: alloc: add Vec::pop Alice Ryhl
2025-03-20 13:52 ` [PATCH 3/5] rust: alloc: add Vec::push_within_capacity Alice Ryhl
2025-03-20 22:17   ` Benno Lossin
2025-03-21 15:22   ` Tamir Duberstein
2025-03-20 13:52 ` [PATCH 4/5] rust: alloc: add Vec::drain_all Alice Ryhl
2025-03-20 22:12   ` Tamir Duberstein
2025-03-21  7:41     ` Alice Ryhl
2025-03-20 13:53 ` [PATCH 5/5] rust: alloc: add Vec::retain Alice Ryhl
2025-03-21 15:24   ` Tamir Duberstein
2025-04-22  9:48     ` Alice Ryhl
2025-03-21 12:11 ` [PATCH 0/5] Additional methods for Vec Alice Ryhl
  -- strict thread matches above, loose matches on Subject: below --
2025-03-20 22:21 [PATCH 5/5] rust: alloc: add Vec::retain Benno Lossin

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.