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

Add collect_in for iterators. #12

Closed
wants to merge 1 commit into from

Conversation

derekdreery
Copy link
Contributor

This adds an extension trait for a new iterator method collect_in, that allows using collect on a bump allocator.

I've made the PR to stimulate discussion, it didn't take very long so feel free to reject if you feel it doesn't fit.

Copy link
Owner

@fitzgen fitzgen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer not to modify src/collections/* as much as possible, as it will make updating to newer versions of the std collections that much harder.

I totally see the benefit here (I've felt the pain of having to use extend with a default instance rather than collect), but I am also a little hesitant to diverge from std even further. I'd like for the eventual replacement of bumpalo::collections with allocator-parameterised std::collections to be as smooth as possible...

I think this is OK though, if we move it to a new collections_traits submodule.

@@ -2339,3 +2346,44 @@ where
}
}
}

/// Similar to `std::iter::FromIterator`, but for a bump vec.
pub trait FromIteratorBump<'bump, A> {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's name this FromIteratorIn and its method from_iter_in

fn collect_in_a_bump_arena() {
use bumpalo::collections::vec::{IteratorBump, Vec};
let b = Bump::new();
(0..10_000).collect_in::<Vec<_>>(&b);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's also test that it contains the items we expect.

@derekdreery
Copy link
Contributor Author

Just out of interest, how will the new collections in std work? Will they take an allocator? Is there some documentation I can read?

@fitzgen
Copy link
Owner

fitzgen commented Apr 2, 2019

Just out of interest, how will the new collections in std work? Will they take an allocator? Is there some documentation I can read?

It isn't 100% clear yet (will probably require a new RFC to sort it all out) but the few bits of std::collections that are parameterised over an allocator have additional constructors for passing the allocator in by reference.

@derekdreery
Copy link
Contributor Author

Aa I see, so we can replace this when the time comes. I'll just do the tidying up you've suggested.

@fitzgen
Copy link
Owner

fitzgen commented Dec 20, 2019

Going to close this due to inactivity -- @derekdreery if you want to rebase and do the tidying up mentioned above, I'll be happy to reopen and merge in the future!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants