2018-02-19 20:15:52 +00:00
|
|
|
// Copyright (C) 2018 Thiago Santos <thiagossantos@gmail.com>
|
|
|
|
// Sebastian Dröge <sebastian@centricular.com>
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
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 {
|
|
|
|
c.get_next()
|
|
|
|
} else {
|
|
|
|
c.get_previous()
|
|
|
|
}
|
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 {
|
2018-02-19 20:15:52 +00:00
|
|
|
stream_info: self.get_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 {
|
2018-02-19 20:15:52 +00:00
|
|
|
stream_info: self.get_previous(),
|
2018-03-02 19:06:45 +00:00
|
|
|
direction_forward: false,
|
2018-02-19 20:15:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|