-
Notifications
You must be signed in to change notification settings - Fork 112
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 CollectIn, FromIteratorIn traits to allow for easier construction #125
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.
Thanks! Looks good to me, but needs a cargo fmt
before merging.
tests/collect_in.rs
Outdated
} | ||
|
||
|
||
} |
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.
Can you make sure there is a newline at the end of the file? I think running cargo fmt
will do this.
(Prior art, for posterity: #12) |
Oh wow, didn't see this prior implementation (mainly because I grepped for |
No, this PR is fine, since it isn't modifying the files that are borrowed from |
https://github.com/fitzgen/bumpalo/pull/125/checks?check_run_id=3929433788#step:6:80
|
Gotta love deref coercion changes. Should be fixed now (tested with |
src/collections/vec.rs
Outdated
impl<'bump, T> FromIteratorIn<T> for Vec<'bump, T> { | ||
type Alloc = &'bump Bump; | ||
fn from_iter_in<I>(iter: I, alloc: Self::Alloc) -> Self | ||
where | ||
I: IntoIterator<Item = T>, | ||
{ | ||
Vec::from_iter_in(iter, alloc) | ||
} | ||
} | ||
|
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.
Can you avoid modifying the files that are copied from std
? This makes it easier to update these files in the future.
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.
Oh, I didn't realize these were straight from std
. I'll move the impls back to their original place, sorry!
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.
Thanks!
Currently, building
Bump
-parameterized collections from iterators is a little verbose, e.g.while a normal
Vec
can be constructed directly using.collect()
. Having to wrap an entire chain in a method call is ugly for longer expressions, and I find myself using.apply(|iter| Vec::from_iter_in(iter, &bump))
from theapply
crate a lot to avoid extra indentation.This PR adds 2 new traits,
FromIteratorIn
, and an extension traitCollectIn
on allIterator
s that allows for simpler constructor of bump-parameterized structures. Currently,Vec
andString
implementFromIteratorIn
, and future collections should try to do the same if possible.On iterators,
CollectIn
allows a more chainable syntax for constructing these collections:Quickcheck-based tests are also included and passing.