rust-lang / rust-lang/rfcs

`pushed` for returning a mutable reference to the pushed element.

Open
#1,821 10 comments 15 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

T-libs
Dominant language
Markdown
Stars
6.6k
Forks
1.7k
Avg merge
16h 14m
Merged PRs (30d)
1

Description

It is annoying to manually fetch the last element, which is unsurprisingly quite common after a push. The most obvious thing would be to make Vec::<T>::push() return a &mut T, but this is strictly speaking a breaking change. It would be cool to get some crater data on whether this in practice is an issue (i.e. if people don't put the ; after push() in functions returning ()).

The more realistic change is to add a method, push_ref, returning &mut T.

Contributor guide

No contributing guide indexed for this repository

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

The issue proposes adding Vec::push_ref to return a mutable reference to the pushed element, and asks for crater data about changing push() itself. Start by reviewing the API and compatibility questions described in the issue; done means the breaking-change impact is measured and a clear decision is documented.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
backend-api-design
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.