Tracking Issue for Vec::pop_if
· Issue #122741 · rust-lang/rust (original) (raw)
Feature gate: #![feature(vec_pop_if)]
This feature adds the Vec::pop_if
method, which takes a predicate, evaluates it with the last element in the Vec
if present, and returns the item if the predicate returns true
. This makes it possible to conditionally remove the last element without the use of unwrap
.
Public API
impl Vec { pub fn pop_if(&mut self, f: impl FnOnce(&mut T) -> bool) -> Option; }
Steps / History
- ACP: pop_if or Entry/Peek-like API for Vec and VecDeque libs-team#208
- Implementation: Implement Vec::pop_if #123107
- Final comment period (FCP)1: Tracking Issue for Vec::pop_if #122741 (comment)
- Stabilization PR: Stabilize vec_pop_if #135488
Unresolved Questions
- Do we want a
VecDeque::pop_front_if
andVecDeque::pop_back_if
API under this as well?- Separate tracking issue: Tracking Issue for VecDeque::pop_front_if & VecDeque::pop_back_if #135889