diff --git a/lib/src/default_index/rev_walk.rs b/lib/src/default_index/rev_walk.rs index 9c291f919..36eb0ec0f 100644 --- a/lib/src/default_index/rev_walk.rs +++ b/lib/src/default_index/rev_walk.rs @@ -16,7 +16,7 @@ use std::cmp::{max, Reverse}; use std::collections::{BinaryHeap, HashMap, HashSet}; -use std::iter::FusedIterator; +use std::iter::{Fuse, FusedIterator}; use std::ops::Range; use smallvec::SmallVec; @@ -48,6 +48,29 @@ pub(super) trait RevWalk { } } +/// Adapter that turns `Iterator` into `RevWalk` by dropping index argument. +/// +/// As the name suggests, the source object is usually a slice or `Vec`. +#[derive(Clone, Debug)] +pub(super) struct EagerRevWalk { + iter: Fuse, +} + +impl EagerRevWalk { + #[allow(unused)] // TODO + pub fn new(iter: T) -> Self { + EagerRevWalk { iter: iter.fuse() } + } +} + +impl RevWalk for EagerRevWalk { + type Item = T::Item; + + fn next(&mut self, _index: &I) -> Option { + self.iter.next() + } +} + /// Adapter that turns `RevWalk` into `Iterator` by attaching borrowed `index`. #[derive(Clone, Debug)] #[must_use]