Skip to content
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

Tracking Issue for Vec::pop_if #122741

Open
2 of 5 tasks
avandesa opened this issue Mar 19, 2024 · 0 comments
Open
2 of 5 tasks

Tracking Issue for Vec::pop_if #122741

avandesa opened this issue Mar 19, 2024 · 0 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

@avandesa
Copy link
Contributor

avandesa commented Mar 19, 2024

Feature gate: #![feature(vec_pop_if)]

This feature adds the Vec::pop_if method, which takes a predicate, evaluates it with the last element in the Vec if present, and returns the item if the predicate returns true. This makes it possible to conditionally remove the last element without the use of unwrap.

Public API

// core::magic

impl<T> Vec<T> {
    pub fn pop_if<F>(&mut self, f: F) -> Option<T>
        where F: FnOnce(&mut T) -> bool;
}

Steps / History

Unresolved Questions

  • Do we want a VecDeque::pop_front_if and VecDeque::pop_back_if API under this as well?

Footnotes

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

@avandesa avandesa 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 Mar 19, 2024
@avandesa avandesa mentioned this issue Mar 26, 2024
2 tasks
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Mar 27, 2024
Implement `Vec::pop_if`

This PR adds `Vec::pop_if` to the public API, behind the `vec_pop_if` feature.

```rust
impl<T> Vec<T> {
    pub fn pop_if<F>(&mut self, f: F) -> Option<T>
        where F: FnOnce(&mut T) -> bool;
}
```

Tracking issue: rust-lang#122741

## Open questions

- [ ] Should the first unit test be split up?
- [ ] I don't see any guidance on ordering of methods in impl blocks, should I move the method elsewhere?
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Mar 27, 2024
Rollup merge of rust-lang#123107 - avandesa:vec_pop_if, r=joboet

Implement `Vec::pop_if`

This PR adds `Vec::pop_if` to the public API, behind the `vec_pop_if` feature.

```rust
impl<T> Vec<T> {
    pub fn pop_if<F>(&mut self, f: F) -> Option<T>
        where F: FnOnce(&mut T) -> bool;
}
```

Tracking issue: rust-lang#122741

## Open questions

- [ ] Should the first unit test be split up?
- [ ] I don't see any guidance on ordering of methods in impl blocks, should I move the method elsewhere?
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