gstreamer-rs/gstreamer-pbutils/src/discoverer_stream_info.rs

48 lines
1.1 KiB
Rust
Raw Normal View History

2020-12-15 10:53:31 +00:00
// Take a look at the license at the top of the repository in the LICENSE file.
use crate::{prelude::*, DiscovererStreamInfo};
#[derive(Debug)]
pub struct Iter {
stream_info: Option<DiscovererStreamInfo>,
2018-03-02 19:06:45 +00:00
direction_forward: bool,
}
impl Iterator for Iter {
type Item = DiscovererStreamInfo;
fn next(&mut self) -> Option<DiscovererStreamInfo> {
let current = self.stream_info.take();
self.stream_info = match current {
Some(ref c) => {
// Decide on the direction
if self.direction_forward {
2021-04-11 19:39:50 +00:00
c.next()
} else {
2021-04-11 19:39:50 +00:00
c.previous()
}
2018-03-02 19:06:45 +00:00
}
None => None,
};
current
}
}
impl DiscovererStreamInfo {
pub fn next_iter(&self) -> Iter {
Iter {
2021-04-11 19:39:50 +00:00
stream_info: self.next(),
2018-03-02 19:06:45 +00:00
direction_forward: true,
}
}
pub fn previous_iter(&self) -> Iter {
Iter {
2021-04-11 19:39:50 +00:00
stream_info: self.previous(),
2018-03-02 19:06:45 +00:00
direction_forward: false,
}
}
}
impl std::iter::FusedIterator for Iter {}