Add method for consuming a Vec and taking one element.
Nobody has claimed this yet.
- Dominant language
- Markdown
- Stars
- 6.6k
- Forks
- 1.7k
- Avg merge
- 16h 14m
- Merged PRs (30d)
- 1
Description
Sometimes I want to take a single element from a Vec and throw the rest of the Vec away. I can do this using swap_remove then dropping the Vec (or letting it fall out of scope) but it would be clearer and slightly more efficient if there was a method for doing this directly.
I propose adding this method to Vec:
impl<T> Vec<T> {
/// Take a single element of a vector and return it, consuming the
/// vector. If `index` is invalid the original vector is returned.
pub fn into_element(self, index: usize) -> Result<T, Vec<T>> {
...
}
}
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 reviewing the proposed Vec::into_element signature and the six-comment discussion. The payload identifies no implementation files or tests, so first determine the applicable RFC process and affected Rust API area. Done would require resolving the proposal's design and documenting an accepted decision.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- developer-experience
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100