gstreamer/audio/video: Correctly implement ExactSizeIterator

len() is optional but size_hint() must return the correct values. Also
this shouldn't return the overall length but the remaining length.
This commit is contained in:
Sebastian Dröge 2020-10-09 11:30:44 +03:00
parent b7b29ee55a
commit b32fc568da
2 changed files with 20 additions and 8 deletions

View file

@ -263,14 +263,20 @@ impl Iterator for AudioFormatIterator {
Some(fmt)
}
}
fn size_hint(&self) -> (usize, Option<usize>) {
if self.idx == self.len {
return (0, Some(0));
}
impl ExactSizeIterator for AudioFormatIterator {
fn len(&self) -> usize {
self.len
let remaining = (self.len - self.idx) as usize;
(remaining, Some(remaining))
}
}
impl ExactSizeIterator for AudioFormatIterator {}
impl DoubleEndedIterator for AudioFormatIterator {
fn next_back(&mut self) -> Option<Self::Item> {
if self.idx >= self.len {

View file

@ -402,14 +402,20 @@ impl Iterator for VideoFormatIterator {
Some(fmt)
}
}
fn size_hint(&self) -> (usize, Option<usize>) {
if self.idx == self.len {
return (0, Some(0));
}
impl ExactSizeIterator for VideoFormatIterator {
fn len(&self) -> usize {
self.len
let remaining = (self.len - self.idx) as usize;
(remaining, Some(remaining))
}
}
impl ExactSizeIterator for VideoFormatIterator {}
impl DoubleEndedIterator for VideoFormatIterator {
fn next_back(&mut self) -> Option<Self::Item> {
if self.idx >= self.len {