forked from mirrors/gstreamer-rs
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)
|
Some(fmt)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
impl ExactSizeIterator for AudioFormatIterator {
|
fn size_hint(&self) -> (usize, Option<usize>) {
|
||||||
fn len(&self) -> usize {
|
if self.idx == self.len {
|
||||||
self.len
|
return (0, Some(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
let remaining = (self.len - self.idx) as usize;
|
||||||
|
|
||||||
|
(remaining, Some(remaining))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl ExactSizeIterator for AudioFormatIterator {}
|
||||||
|
|
||||||
impl DoubleEndedIterator for AudioFormatIterator {
|
impl DoubleEndedIterator for AudioFormatIterator {
|
||||||
fn next_back(&mut self) -> Option<Self::Item> {
|
fn next_back(&mut self) -> Option<Self::Item> {
|
||||||
if self.idx >= self.len {
|
if self.idx >= self.len {
|
||||||
|
|
|
@ -402,14 +402,20 @@ impl Iterator for VideoFormatIterator {
|
||||||
Some(fmt)
|
Some(fmt)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
impl ExactSizeIterator for VideoFormatIterator {
|
fn size_hint(&self) -> (usize, Option<usize>) {
|
||||||
fn len(&self) -> usize {
|
if self.idx == self.len {
|
||||||
self.len
|
return (0, Some(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
let remaining = (self.len - self.idx) as usize;
|
||||||
|
|
||||||
|
(remaining, Some(remaining))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl ExactSizeIterator for VideoFormatIterator {}
|
||||||
|
|
||||||
impl DoubleEndedIterator for VideoFormatIterator {
|
impl DoubleEndedIterator for VideoFormatIterator {
|
||||||
fn next_back(&mut self) -> Option<Self::Item> {
|
fn next_back(&mut self) -> Option<Self::Item> {
|
||||||
if self.idx >= self.len {
|
if self.idx >= self.len {
|
||||||
|
|
Loading…
Reference in a new issue