diff --git a/src/helpers/history.rs b/src/helpers/history.rs index 64ab21a..0a2589f 100644 --- a/src/helpers/history.rs +++ b/src/helpers/history.rs @@ -24,6 +24,11 @@ impl WithHistory { pub fn get(&self, index: usize) -> Option { Buffered::get(self, index) } + + /// Iterate over historical values, starting from the oldest value + pub fn iter(&self) -> impl Iterator { + self.history.iter() + } } impl Buffered for WithHistory { @@ -57,6 +62,24 @@ where } } +impl<'a, T, V> IntoIterator for &'a WithHistory { + type Item = &'a V; + type IntoIter = std::slice::Iter<'a, V>; + + fn into_iter(self) -> Self::IntoIter { + self.history.iter() + } +} + +impl IntoIterator for WithHistory { + type Item = V; + type IntoIter = std::vec::IntoIter; + + fn into_iter(self) -> Self::IntoIter { + self.history.into_iter() + } +} + /// Wrapper for keeping last produced value #[derive(Debug, Clone)] pub struct WithLastValue {