drain_filter_take
Nobody has claimed this yet.
- Dominant language
- Markdown
- Stars
- 6.6k
- Forks
- 1.7k
- Avg merge
- 16h 14m
- Merged PRs (30d)
- 1
Description
Currently we have the unstable Vec::drain_filter:
pub fn drain_filter<F>(&mut self, filter: F) -> DrainFilter<'_, T, F, A>
where
F: FnMut(&mut T) -> bool;
My use case is that I want to perform some side effects in filter, where the side effects would determine whether the item should be drained, but performing the side effects requires moving out the T if the element is to be filtered.
I propose a new method drain_filter_take that takes the form
pub fn drain_filter_take<F>(&mut self, filter: F) // does not return an iterator
where
F: FnMut(T) -> Option<T>;
(I am not sure what a good name would be that clearly indicates it does not return an iterator)
If Some is returned, it replaces the original value; if None is returned, the value is drained. This allows the filter to take ownership of T and only return it if not drained.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading the existing Vec::drain_filter API and the proposed drain_filter_take signature in this issue. A complete contribution would need the ownership and replacement semantics, method naming, and API design to be resolved before implementation; no files or tests are identified in the issue.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- api
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100