-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Change VecMap
's iterators to use wrapper structs instead of typedefs.
#19720
Conversation
If changes like this are desired for the other maps that use typedefs currently (like |
wouldn't a newtype be more correct here? |
It's not clear that we'll be getting trait forwarding any time soon, if ever. As such this is perfectly fine. |
Would it be possible for these to implement DoubleEnded as well? The Vec iterator is ExactSize, so I believe it should be DoubleEnded for these adaptors. If not we should consider a set of adaptors that do permit DoubleEnded iteration. |
So after looking closer at |
#[inline] | ||
fn size_hint(&self) -> (uint, Option<uint>) { | ||
self.iter.size_hint() | ||
} |
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.
Also as a minor style point I tend to "squash" impl-forwarding methods like these to reduce the noise. That is:
impl<'a, V> Iterator<uint> for Keys<'a, V> {
#[inline] fn next(&mut self) -> Option<uint> { self.iter.next() }
#[inline] fn size_hint(&self) -> (uint, Option<uint>) { self.iter.size_hint() }
}
Because it's code that doesn't really "matter". Just trivial boiler-plate.
This is a personal thing though, so I won't block this on it. No real convention. See e.g. btreemap for an actual example of this in our codebase, though.
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'd also prefer that we don't #[inline] these. Want to start cracking down on blind inlining.
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'm in the process of adding DoubleEnded etc anyway, so I'll just squash these down while I'm in here!
e3c5725
to
69d113f
Compare
@gankro Documentation is fixed. |
As mentioned in rust-lang#19663, it is more desirable long-term that iterators be implemented as wrapper structs instead of typedefs. This pull request converts `VecMap` to the preferred solution.
@csouth3 Answering your question, this would be nice for all collections, including |
Using a type alias for iterator implementations is fragile since this exposes the implementation to users of the iterator, and any changes could break existing code. This commit changes the iterators of `VecMap` to use proper new types, rather than type aliases. However, since it is fair-game to treat a type-alias as the aliased type, this is a: [breaking-change].
69d113f
to
81f9a31
Compare
@gankro Got wrecked by the closure unboxing pull that just got merged, hah. |
Change `VecMap`'s iterators to use wrapper structs instead of typedefs. Reviewed-by: Gankro
Change `VecMap`'s iterators to use wrapper structs instead of typedefs. Reviewed-by: Gankro
@gankro Is there anything I need to do to get this moved out of "BAD"? This took the fall for the auto rollup but it wasn't the offending PR. |
Sorry, saw this on my phone and promptly forgot about it 😅 |
Change `VecMap`'s iterators to use wrapper structs instead of typedefs. Reviewed-by: Gankro, Gankro
Brought down by the cruel auto-rollup again :^) |
Using a type alias for iterator implementations is fragile since this exposes the implementation to users of the iterator, and any changes could break existing code. This commit changes the iterators of `VecMap` to use proper new types, rather than type aliases. However, since it is fair-game to treat a type-alias as the aliased type, this is a: [breaking-change].
Using a type alias for iterator implementations is fragile since this
exposes the implementation to users of the iterator, and any changes
could break existing code.
This commit changes the iterators of
VecMap
to useproper new types, rather than type aliases. However, since it is
fair-game to treat a type-alias as the aliased type, this is a:
[breaking-change].