-
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(push_mut)]
This is a tracking issue for Vec::push_mut
and similar methods, as discussed in the comments of this ACP. This adds a way to get a reference to the just-pushed value, which can eliminate having to .unwrap()
or access the back of the list twice.
Public API
// All are `#[must_use]` to suggest using `.push(...)` if you don't need the reference
impl<T> Vec<T> {
#[must_use]
pub fn push_mut(&mut self, value: T) -> &mut T;
#[must_use]
pub fn insert_mut(&mut self, index: usize, element: T) -> &mut T;
#[must_use]
pub fn push_mut_within_capacity(&mut self, value: T) -> Result<&mut T, T>;
}
impl<T> VecDeque<T> {
#[must_use]
pub fn push_front_mut(&mut self, value: T) -> &mut T;
#[must_use]
pub fn push_back_mut(&mut self, value: T) -> &mut T;
#[must_use]
pub fn insert_mut(&mut self, index: usize, value: T) -> &mut T;
}
impl<T> LinkedList<T> {
#[must_use]
pub fn push_front_mut(&mut self, elt: T) -> &mut T;
#[must_use]
pub fn push_back_mut(&mut self, elt: T) -> &mut T
}
Steps / History
- Implementation: Implement
push_mut
#135975 - Final comment period (FCP)
- Stabilization PR
Unresolved Questions
- Does
must_use
make sense? Are there downsides ofpush_mut
vs.push
?
zopsicle, oxalica, Evian-Zhang, petrochenkov and Kobzolrodrimati1992
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.