2020-12-15 10:53:31 +00:00
|
|
|
// Take a look at the license at the top of the repository in the LICENSE file.
|
2018-02-19 20:15:52 +00:00
|
|
|
|
2020-11-22 10:10:54 +00:00
|
|
|
use crate::DiscovererStreamInfo;
|
|
|
|
use crate::DiscovererStreamInfoExt;
|
2018-02-19 20:15:52 +00:00
|
|
|
|
2019-01-22 15:43:29 +00:00
|
|
|
#[derive(Debug)]
|
2018-03-02 19:00:48 +00:00
|
|
|
pub struct Iter {
|
2018-02-19 20:15:52 +00:00
|
|
|
stream_info: Option<DiscovererStreamInfo>,
|
2018-03-02 19:06:45 +00:00
|
|
|
direction_forward: bool,
|
2018-02-19 20:15:52 +00:00
|
|
|
}
|
|
|
|
|
2018-03-02 19:00:48 +00:00
|
|
|
impl Iterator for Iter {
|
2018-02-19 20:15:52 +00:00
|
|
|
type Item = DiscovererStreamInfo;
|
|
|
|
|
|
|
|
fn next(&mut self) -> Option<DiscovererStreamInfo> {
|
|
|
|
let current = self.stream_info.take();
|
2018-07-20 07:21:06 +00:00
|
|
|
self.stream_info = match current {
|
|
|
|
Some(ref c) => {
|
2018-02-19 20:15:52 +00:00
|
|
|
// Decide on the direction
|
|
|
|
if self.direction_forward {
|
2021-04-11 19:39:50 +00:00
|
|
|
c.next()
|
2018-02-19 20:15:52 +00:00
|
|
|
} else {
|
2021-04-11 19:39:50 +00:00
|
|
|
c.previous()
|
2018-02-19 20:15:52 +00:00
|
|
|
}
|
2018-03-02 19:06:45 +00:00
|
|
|
}
|
2018-07-20 07:21:06 +00:00
|
|
|
None => None,
|
2018-02-19 20:15:52 +00:00
|
|
|
};
|
|
|
|
current
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl DiscovererStreamInfo {
|
2018-03-02 19:00:48 +00:00
|
|
|
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,
|
2018-02-19 20:15:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-02 19:00:48 +00:00
|
|
|
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,
|
2018-02-19 20:15:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|