-
Notifications
You must be signed in to change notification settings - Fork 13.4k
std: Stabilize IteratorExt::cloned
#23462
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
Conversation
r? @aturon (rust_highfive has picked a reviewer for you, use r? to override) |
This commit stabilizes the `cloned` iterator after tweaking the signature to require that the iterator is over `&T` instead of `U: Deref<T>`. This method has had time to bake for awhile now and it's not clear whether the `Deref` bound is worth it. Additionally, there aren't clear conventions on when to bound and/or implement the `Deref` trait, so for now the conservative route is to require references instead of `U: Deref<T>`. To change this signature to using `Deref` would technically be a backwards-incompatible change, but it is doubtful that any code will actually break in practice.
eec11b9
to
7c333e9
Compare
I assume Option::cloned will go the same way, since it is very much the same. |
@alexcrichton I have mixed feelings about this signature change -- it's both less flexible, and possibly less clear. Can you expand a bit on the motivation for the change? (I do agree that we don't have a convention yet, but conventions often arise from examples like this.) That said, I don't care too much either way. cc @gankro |
The primary motivation of Deref was to unify & and &mut. Granted: I can't think of any place where you'd only have an &mut but couldn't do & (maybe a generic context...?). Being able to rip through Box's/Rc's/Whatever is just gravy that I wasn't super concerned with. |
I do agree that the signature went a bit south, I was not super happy that type/lifetime parameters needed to be added.
My main motivation was that we have very few functions which are abstract over
If we stabilize |
…uron This commit stabilizes the `cloned` iterator after tweaking the signature to require that the iterator is over `&T` instead of `U: Deref<T>`. This method has had time to bake for awhile now and it's not clear whether the `Deref` bound is worth it. Additionally, there aren't clear conventions on when to bound and/or implement the `Deref` trait, so for now the conservative route is to require references instead of `U: Deref<T>`. To change this signature to using `Deref` would technically be a backwards-incompatible change, but it is doubtful that any code will actually break in practice.
This commit stabilizes the
cloned
iterator after tweaking the signature torequire that the iterator is over
&T
instead ofU: Deref<T>
. This method hashad time to bake for awhile now and it's not clear whether the
Deref
bound isworth it. Additionally, there aren't clear conventions on when to bound and/or
implement the
Deref
trait, so for now the conservative route is to requirereferences instead of
U: Deref<T>
.To change this signature to using
Deref
would technically be abackwards-incompatible change, but it is doubtful that any code will actually
break in practice.