-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Open
Labels
C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCT-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.
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
?
Footnotes
Metadata
Metadata
Assignees
Labels
C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCT-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.