Skip to content

Tracking Issue for Vec::peek_mut #122742

Open

Description

@igneousflock

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?

Footnotes

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

Activity

  1. added
    C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFC
    T-libs-api[DEPRECATED; DO NOT USE]
    on Mar 19, 2024
  2. GrigorenkoPV commented on Mar 22, 2024

    @GrigorenkoPV
    Contributor

    Even though FCP has not started yet, I would like to express a couple of concerns regarding the name. I am not very pleased with either peek or peek_mut for two reasons:

    1. All the other std APIs with peek in name usually revolve around Option<&T> and not an Entry-style API similar to Map's Entry.
    2. The name does not reflect which element it operates on. After some thinking you can probably guess that it means the last element for Vec, similarly to push and pop, but I would argue that peek sounds closer to get, which is not tied to a specific position.

    I would personally prefer something along the lines of "last_entry".

  3. added a commit that references this issue on Jun 14, 2025
  4. added a commit that references this issue on Jun 14, 2025
  5. added a commit that references this issue on Jun 18, 2025
  6. alex-700 commented on Jul 11, 2025

    @alex-700
    Contributor

    The BinaryHeap's PeekMut::pop has this-named parameter on puprose. See comment for the reason.

    Should we avoid the same problem here in Vec's PeekMut::pop?

  7. added 2 commits that reference this issue on Sep 15, 2025
  8. added a commit that references this issue on Sep 15, 2025
  9. added a commit that references this issue on Sep 16, 2025
  10. added a commit that references this issue on Sep 20, 2025
  11. added a commit that references this issue on Sep 24, 2025
  12. added 2 commits that reference this issue on Oct 9, 2025
  13. added 3 commits that reference this issue on Nov 8, 2025
  14. added
    T-libsRelevant to the library team, which will review and decide on the PR/issue.
    and removed
    T-libs-api[DEPRECATED; DO NOT USE]
    on Aug 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCT-libsRelevant to the library team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions