Tracking Issue for Vec::peek_mut · Issue #122742 · rust-lang/rust (original) (raw)

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 Vec { 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

Unresolved Questions

  1. https://std-dev-guide.rust-lang.org/feature-lifecycle/stabilization.html