mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer-rs.git
synced 2024-11-25 19:11:06 +00:00
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:
parent
b7b29ee55a
commit
b32fc568da
2 changed files with 20 additions and 8 deletions
|
@ -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 {
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue