Skip to content
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

Implementation of size_hint for ImageBuffer iterators should return the same as the ExactSizeIterator::len impl. #1789

Closed
GabrielDertoni opened this issue Sep 17, 2022 · 0 comments · Fixed by #1790

Comments

@GabrielDertoni
Copy link
Contributor

GabrielDertoni commented Sep 17, 2022

The docs for std::iter::ExactSizeIterator state that

When implementing an ExactSizeIterator, you must also implement Iterator. When doing so, the implementation of Iterator::size_hint must return the exact size of the iterator.

however the current implementation of Iterator for the ImageBuffer iterators do not have such behaviour and use the default implementation that returns (0, None) even though these iterators do implement std::iter::ExactSizeIterator.

Expected

Every iterator that implements std::iter::ExactSizeIterator should also return the exact size in the size_hint function.

Actual behaviour

Implementations currently return the default (0, None).

Reproduction steps

The following test fails:

let image = RgbImage::from_raw(1, 1 vec![0; 3]).unwrap();
let iter = image.pixels();
let exact_len = ExactSizeIterator::len(&iter);
assert_eq!(iter.size_hint(), (exact_len, Some(exact_len)));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant