-
-
Notifications
You must be signed in to change notification settings - Fork 14.3k
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 RFCI-lang-radarItems that are on lang's radar and will need eventual work or consideration.Items that are on lang's radar and will need eventual work or consideration.T-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.disposition-mergeThis issue / PR is in PFCP or FCP with a disposition to merge it.This issue / PR is in PFCP or FCP with a disposition to merge it.final-comment-periodIn the final comment period and will be merged soon unless new substantive objections are raised.In the final comment period and will be merged soon unless new substantive objections are raised.
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;
}
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
Doesmust_usemake sense? Are there downsides ofpush_mutvs.push?
zopsicle, oxalica, Evian-Zhang, petrochenkov, Kobzol and 14 morerodrimati1992, MalekiRe, balt-dev, srkaj and marmitar
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 RFCI-lang-radarItems that are on lang's radar and will need eventual work or consideration.Items that are on lang's radar and will need eventual work or consideration.T-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.disposition-mergeThis issue / PR is in PFCP or FCP with a disposition to merge it.This issue / PR is in PFCP or FCP with a disposition to merge it.final-comment-periodIn the final comment period and will be merged soon unless new substantive objections are raised.In the final comment period and will be merged soon unless new substantive objections are raised.