Open
Description
Feature gate: #![feature(push_mut)]
This is a tracking issue for Vec::push_mut
, 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
#[must_use = "if you don't need a reference to the value, use Vec::push")]
pub fn push_mut(&mut self, value: T) -> &mut T { /* ... */ }
Steps / History
Unresolved Questions
None
Activity
push_mut
#135975[-]Tracking Issue for push_mut[/-][+]Tracking Issue for `Vec::push_mut`[/+]balt-dev commentedon Jan 24, 2025
Here's an example from the documentation:
balt-dev commentedon Feb 18, 2025
(Note: I did go back and change the
// Polonius moment.
comment to something more descriptive.)Vec::push_mut
andVec::insert_mut
rust-lang/libs-team#579balt-dev commentedon Jun 9, 2025
Thoughts on anunsafe push_raw
that returns a*mut T
?Actually, wait, that's unnecessary since you can just downgrade the reference to a pointer in all cases.