oxc-project / oxc-project/backlog
Method to convert a `Vec<T>` to an iterator of `Box<T>`s
Nobody has claimed this yet.
- Dominant language
- No language data
- Stars
- 7
- Forks
- 0
- PR merge metrics
- No merged PRs in 30d
Description
Similar to #161.
Now that we have our own Vec implementation, we can add some APIs which were previously impossible.
Vec::into_boxes_iter converts a Vec<T> into an iterator of Box<T>s:
API:
impl<'a, T> Vec<'a, T> {
/// Consume a `Vec` and return an iterator which yields
/// each item of the `Vec` as a `Box`.
fn into_boxes_iter(self) -> IntoBoxesIter<'a, T> { /* ... */ }
}
struct IntoBoxesIter<'a, T> { /* ... */ }
impl<'a, T> Iterator for IntoBoxesIter<'a, T> {
type Item = Box<'a, T>;
fn next(&mut self) -> Option<Box<'a, T>> { /* ... */ }
}
Usage:
let vec: Vec<'a, Foo> = get_vec_somehow();
for boxed_foo in vec.into_boxes_iter() {
// `boxed_foo` is `Box<'a, Foo>`.
// Do something with the box.
}
This could replace a common pattern of using vec.drain(..) and then having to allocate the yielded items back into the arena.
The Boxes yielded by into_boxes_iter's iterator point directly to the data in the original. No data gets copied, and it performs no allocations.
std's Vec cannot offer this API because when a Vec is dropped, it must deallocate with the same layout as it was originally allocated with. But because our Vec and Box are not Drop, we don't have that restriction.
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 locating the custom Vec and Box implementations and inspect how Vec ownership and iteration currently work. Add the specified into_boxes_iter API and iterator, then verify that iteration yields boxes pointing to the original data without copying or allocating.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100