-
Notifications
You must be signed in to change notification settings - Fork 2
Implementing ExactSizeIterator
#16
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
base: main
Are you sure you want to change the base?
Conversation
Also implemented `FusedIterator`.
parasyte
left a comment
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.
Thank you for the contribution! Did you have any additional context for the utility of exact size iterator for error source iteration?
For comparison, core::error::Source implements FusedIterator, but not ExactSizeIterator. This crate is intended to be compatible with the nightly-only error_iter feature, not to extend its capabilities.
I also haven't seen any discussion on whether ExactSizeIterator should or will be implemented for core::error::Source. Are you aware of any?
| fn size_hint(&self) -> (usize, Option<usize>) { | ||
| let mut count = 0_usize; | ||
| let mut next = self.inner; | ||
| while let Some(error) = next { |
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.
Since size_hint is now iterating the remainder of the chain, I don't know if that could be called an optimization (using terminology from the size_hint documentation).
What you have here is the correct thing to do for ExactSizeIterator, however.
The intention was to able to optimize It may not be worth it, but I figured that calculation would be cheap enough that it's still a net benefit.
I am not. |
|
I don't really know what to do here. If we make the iterator implement
If the goal was to use On the other hand, having the Sorry I don't have a decision, here. But I wanted to offer my thoughts so that it doesn't look like this was forgotten. |
I appreciate that. Some thoughts, in case it's helpful: If the goal of this crate is to mirror the current behavior of the unstable feature, then I can certainly understand only adding If you'd like to expand this crate beyond the functionality of the feature, then maybe some or all of this PR is worth considering? |
|
I'm trying to think of a way to incorporate this, and an optional feature flag might be the best way to make progress. But before that, I think it would be prudent to benchmark the before and after cases with |
Also implemented
FusedIterator