diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2025-01-24 16:25:45 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-01-24 16:25:45 +0100 |
| commit | b344e14bded157089786de60d17f71feb2ce14f4 (patch) | |
| tree | 86b42f2b4413cc4b00d51cd3ba7db474246ad238 /library/alloc/src | |
| parent | c459b17d24c34fe0169f5399c4b09a825edb4f3f (diff) | |
| parent | b2ad126a55b3c92a0e09d1749565376c3424ac01 (diff) | |
| download | rust-b344e14bded157089786de60d17f71feb2ce14f4.tar.gz rust-b344e14bded157089786de60d17f71feb2ce14f4.zip | |
Rollup merge of #135956 - GrigorenkoPV:vec_pop_off, r=dtolnay
Make `Vec::pop_if` a bit more presentable #135488 minus stabilization. As suggested in https://github.com/rust-lang/rust/pull/135488#issuecomment-2608108210. r? tgross35
Diffstat (limited to 'library/alloc/src')
| -rw-r--r-- | library/alloc/src/vec/mod.rs | 11 |
1 files changed, 4 insertions, 7 deletions
diff --git a/library/alloc/src/vec/mod.rs b/library/alloc/src/vec/mod.rs index cd2afd7a473..84e1449a50e 100644 --- a/library/alloc/src/vec/mod.rs +++ b/library/alloc/src/vec/mod.rs @@ -2511,9 +2511,9 @@ impl<T, A: Allocator> Vec<T, A> { } } - /// Removes and returns the last element in a vector if the predicate + /// Removes and returns the last element from a vector if the predicate /// returns `true`, or [`None`] if the predicate returns false or the vector - /// is empty. + /// is empty (the predicate will not be called in that case). /// /// # Examples /// @@ -2528,12 +2528,9 @@ impl<T, A: Allocator> Vec<T, A> { /// assert_eq!(vec.pop_if(pred), None); /// ``` #[unstable(feature = "vec_pop_if", issue = "122741")] - pub fn pop_if<F>(&mut self, f: F) -> Option<T> - where - F: FnOnce(&mut T) -> bool, - { + pub fn pop_if(&mut self, predicate: impl FnOnce(&mut T) -> bool) -> Option<T> { let last = self.last_mut()?; - if f(last) { self.pop() } else { None } + if predicate(last) { self.pop() } else { None } } /// Moves all the elements of `other` into `self`, leaving `other` empty. |
