use store::iter::{BlockRootsIterator, StateRootsIterator}; use types::{Hash256, Slot}; pub type ReverseBlockRootIterator<'a, E, S> = ReverseHashAndSlotIterator>; pub type ReverseStateRootIterator<'a, E, S> = ReverseHashAndSlotIterator>; pub type ReverseHashAndSlotIterator = ReverseChainIterator<(Hash256, Slot), I>; /// Provides a wrapper for an iterator that returns a given `T` before it starts returning results of /// the `Iterator`. pub struct ReverseChainIterator { first_value_used: bool, first_value: T, iter: I, } impl ReverseChainIterator where T: Sized, I: Iterator + Sized, { pub fn new(first_value: T, iter: I) -> Self { Self { first_value_used: false, first_value, iter, } } } impl Iterator for ReverseChainIterator where T: Clone, I: Iterator, { type Item = T; fn next(&mut self) -> Option { if self.first_value_used { self.iter.next() } else { self.first_value_used = true; Some(self.first_value.clone()) } } }