-
Notifications
You must be signed in to change notification settings - Fork 118
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
Conversation
There was a problem hiding this 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> { |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
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 |
Aa I see, so we can replace this when the time comes. I'll just do the tidying up you've suggested. |
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! |
This adds an extension trait for a new iterator method
collect_in
, that allows usingcollect
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.