Tracking Issue for Vec::push_mut (original) (raw)

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 Vec { #[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 VecDeque { #[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 LinkedList { #[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

Unresolved Questions