rust-lang / rust-lang/rust

Tracking Issue for `Vec::peek_mut`

Open
#122,742 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

C-tracking-issue T-libs
Dominant language
Rust
Stars
119k
Forks
16.2k
PR merge metrics
PR metrics pending

Description

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<T> Vec<T> {
    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
  • Should this be named peek or peek_mut?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the vec_peek_mut feature gate and compare the proposed Vec::peek_mut and PeekMut API with BinaryHeap::peek_mut. Review the linked ACP and resolve the naming question before implementing the pending API. Done means the implementation, FCP, and stabilization PR steps are completed.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
api
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.