2019-04-23 12:34:24 +02:00
|
|
|
|
//! Spline [`Iterator`], in a nutshell.
|
|
|
|
|
//!
|
|
|
|
|
//! You can iterate over a [`Spline<K, V>`]’s keys with the [`IntoIterator`] trait on
|
|
|
|
|
//! `&Spline<K, V>`. This gives you iterated [`Key<K, V>`] keys.
|
|
|
|
|
//!
|
|
|
|
|
//! [`Spline<K, V>`]: crate::spline::Spline
|
|
|
|
|
//! [`Key<K, V>`]: crate::key::Key
|
|
|
|
|
|
2019-04-19 13:39:37 +02:00
|
|
|
|
use crate::{Key, Spline};
|
|
|
|
|
|
|
|
|
|
/// Iterator over spline keys.
|
|
|
|
|
///
|
2019-04-23 12:34:24 +02:00
|
|
|
|
/// This iterator type is guaranteed to iterate over sorted keys.
|
2019-04-19 13:39:37 +02:00
|
|
|
|
pub struct Iter<'a, T, V> where T: 'a, V: 'a {
|
2019-04-23 12:34:24 +02:00
|
|
|
|
spline: &'a Spline<T, V>,
|
2019-04-19 13:39:37 +02:00
|
|
|
|
i: usize
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<'a, T, V> Iterator for Iter<'a, T, V> {
|
|
|
|
|
type Item = &'a Key<T, V>;
|
|
|
|
|
|
|
|
|
|
fn next(&mut self) -> Option<Self::Item> {
|
2019-04-23 12:34:24 +02:00
|
|
|
|
let r = self.spline.0.get(self.i);
|
2019-04-19 13:39:37 +02:00
|
|
|
|
|
|
|
|
|
if let Some(_) = r {
|
|
|
|
|
self.i += 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
r
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<'a, T, V> IntoIterator for &'a Spline<T, V> {
|
|
|
|
|
type Item = &'a Key<T, V>;
|
|
|
|
|
type IntoIter = Iter<'a, T, V>;
|
|
|
|
|
|
|
|
|
|
fn into_iter(self) -> Self::IntoIter {
|
|
|
|
|
Iter {
|
2019-04-23 12:34:24 +02:00
|
|
|
|
spline: self,
|
2019-04-19 13:39:37 +02:00
|
|
|
|
i: 0
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|