-
Notifications
You must be signed in to change notification settings - Fork 185
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 explicit ZeroVec and VarZeroVec iterator types #4487
Comments
This was a deliberate choice so as not to overcommit to the implementation of the iterator, especially since we are returning adapters. We can write explicit adapters, however:
The compiler should allow you to do this as long as both iterators come from the same method. It's intermediate methods that cause this problem.
This is simply not the case; that's not how |
Yes and I have intermediate methods. I worked around the problem in my datetime PR by using the
What I was referring to is #2603. What I saw in the bytecode while working on that change was a mess of iterator abstractions ( I wanted to discuss the ZeroVec iterators because they are currently written as pub fn iter(&self) -> impl DoubleEndedIterator<Item = T> + ExactSizeIterator<Item = T> + '_ {
self.as_ule_slice().iter().copied().map(T::from_unaligned)
} That impl is probably fine because I think |
Also it makes it trickier to use with EDIT: Actually it is rust-lang/rust#63063 which is not stable yet. |
Ah, that's a different problem than I would measure this. 99% of the time iterator chains are more efficient than loop iteration. Either way, I'm in favor of using concrete named types; I just didn't choose to do this initially. We should be very careful to give them a limited API though. |
The standard library exports concrete types for iterators. However, our ZeroVec types only return
impl Iterator
. This limits a certain amount of flexibility; for example, you can't put multiple iterators together into a list because the compiler doesn't know that theimpl Iterator
s are going to be the same type.I also question whether
impl Iterator
is highly efficient in terms of code size and performance. I remember pulling apart some spaghetti iterators into procedural code and getting a boost. Returning a concrete type could make code simpler to compile.Thoughts? @Manishearth
The text was updated successfully, but these errors were encountered: