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