Skip to content

Tracking Issue for Vec::peek_mut #122742

Open
@avandesa

Description

@avandesa

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCT-libs-apiRelevant to the library API 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