vecdb/iterators/
mod.rs

1use std::iter::FusedIterator;
2
3mod boxed;
4mod typed;
5mod writer;
6
7pub use boxed::*;
8pub use typed::*;
9pub use writer::*;
10
11/// Base trait for vector iterators with positioning capabilities.
12pub trait VecIterator: ExactSizeIterator + FusedIterator {
13    /// Sets the current position to the given usize index.
14    fn set_position_to(&mut self, i: usize);
15
16    /// Gets the item at the given usize index.
17    #[inline(always)]
18    fn get_at(&mut self, i: usize) -> Option<Self::Item> {
19        self.set_position_to(i);
20        self.next()
21    }
22
23    /// Gets the item at the given usize index, panics if not found.
24    #[inline(always)]
25    fn get_at_unwrap(&mut self, i: usize) -> Self::Item {
26        self.get_at(i).unwrap()
27    }
28
29    /// Gets the item at the given usize index, returns default if not found.
30    #[inline(always)]
31    fn get_at_or_default(&mut self, i: usize) -> Self::Item
32    where
33        Self::Item: Default,
34    {
35        self.get_at(i).unwrap_or_default()
36    }
37
38    /// Sets the exclusive end boundary to the given usize index.
39    fn set_end_to(&mut self, i: usize);
40
41    /// Returns the total number of elements in the underlying Vector.
42    fn vec_len(&self) -> usize;
43}