Open
Description
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<T> Vec<T> {
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
orEntry
/Peek
-like API forVec
andVecDeque
libs-team#208 - Implementation: pending
- Final comment period (FCP)1
- Stabilization PR
Unresolved Questions
- Should this be named
peek
orpeek_mut
?