Tracking Issue for Vec::peek_mut
· Issue #122742 · rust-lang/rust (original) (raw)
Feature gate: #![feature(vec_peek_mut)]
This feature adds Vec::peek_mut
, which returns a PeekMut
struct. It is analogous to [BinaryHeap::peek_mut]
and enables users to conditionally modify and remove the last element of a Vec
without having to call unwrap
.
Public API
impl Vec { pub fn peek_mut(&mut self) -> Option<PeekMut<'_, T>>; }
pub struct PeekMut<'a, T>;
impl<'a, T> PeekMut<'a, T> { pub fn pop(self) -> T; }
// impl Deref
/DerefMut
for PeekMut
Steps / History
- ACP: pop_if or Entry/Peek-like API for Vec and VecDeque libs-team#208
- Implementation: pending
- Final comment period (FCP)1
- Stabilization PR
Unresolved Questions
- Should this be named
peek
orpeek_mut
?