-
Notifications
You must be signed in to change notification settings - Fork 1
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 I: Iterator
to I: IntoIterator
#2
Comments
@jerry73204 I don't think we should do this. The reason is that the iterator is cloned MANY times. It could even be cloned millions of times, depending on the amount of data and the algorithm. The iterator is being used to look up the If you think there might be a better way to do this, we can do that, but I would prefer to avoid breaking changes as well. Let me know what you think. |
Even we do not have To recap, my thought is that the original design already suffers cloning cost issue. Having |
The implementation of Additionally, the iterator which is cloned is only two pointers: https://doc.rust-lang.org/beta/src/core/slice/iter.rs.html#64-70 The intended use case is to pass If you only have five small data points, then it probably isn't that impactful for you if there are a few extra allocations because the vector is cloned. However, it might come as a surprise to a user who has a dataset of millions of elements, in which case execution may never terminate if they accidentally pass the whole data structure. Unfortunately, there is no container trait that allows borrowing the underlying items ( As a stop gap measure, we just take an arbitrary clonable iterator over the values rather than an abstraction over both the iterator and the iterable collection (collection traits are not possible due to a lack of generic associated type as per above RFC). The user is forced by the type system to clone the values of the iterator from the underlying references. This is done with Let me know if there are any remaining issues. If we need to improve the documentation here to be more transparent, I would be glad to do that. |
Very interesting finding. For the copying cost, your concern is correct. The owning iterator Better if you can clarify it more in documentation and suggest |
Consensus::model()
for example, usingI: IntoIterator
instead ofI: Iterator
allows users to pass a vector directly. It gives us some convenient to avoid writingdata.into_iter()
.The text was updated successfully, but these errors were encountered: