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
Unresolved Questions
- Should this be named
peek or peek_mut?
Feature gate:
#![feature(vec_peek_mut)]This feature adds
Vec::peek_mut, which returns aPeekMutstruct. It is analogous to[BinaryHeap::peek_mut]and enables users to conditionally modify and remove the last element of aVecwithout having to callunwrap.Public API
Steps / History
pop_iforEntry/Peek-like API forVecandVecDequelibs-team#208Unresolved Questions
peekorpeek_mut?Footnotes
https://std-dev-guide.rust-lang.org/feature-lifecycle/stabilization.html ↩