Skip to content

Tracking Issue for Vec::push_mut #135974

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
1 of 3 tasks
balt-dev opened this issue Jan 24, 2025 · 2 comments
Open
1 of 3 tasks

Tracking Issue for Vec::push_mut #135974

balt-dev opened this issue Jan 24, 2025 · 2 comments
Labels
C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@balt-dev
Copy link

balt-dev commented Jan 24, 2025

Feature gate: #![feature(push_mut)]

This is a tracking issue for Vec::push_mut, as discussed in the comments of this ACP. This adds a way to get a reference to the just-pushed value, which can eliminate having to .unwrap() or access the back of the list twice.

Public API

#[must_use = "if you don't need a reference to the value, use Vec::push")]
pub fn push_mut(&mut self, value: T) -> &mut T { /* ... */ }

Steps / History

Unresolved Questions

  • None yet
@balt-dev balt-dev added C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. labels Jan 24, 2025
@balt-dev balt-dev changed the title Tracking Issue for push_mut Tracking Issue for Vec::push_mut Jan 24, 2025
@balt-dev
Copy link
Author

Here's an example from the documentation:

#![feature(push_mut)]

let mut vec = vec![];
// Polonius moment.
let last = if let Some(v) = vec.last_mut() { v } else { vec.push_mut(0) };
*last += 6;
assert_eq!(vec, [6]);

@balt-dev
Copy link
Author

balt-dev commented Feb 18, 2025

(Note: I did go back and change the // Polonius moment. comment to something more descriptive.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

1 participant