1use std::vec::Vec;
5
6#[derive(Debug, Clone)]
13pub struct NeoIterator<T> {
14 data: Vec<T>,
15 cursor: usize,
16}
17
18impl<T> NeoIterator<T> {
19 pub fn new(data: Vec<T>) -> Self {
21 Self { data, cursor: 0 }
22 }
23
24 pub fn has_next(&self) -> bool {
26 self.cursor < self.data.len()
27 }
28
29 pub fn len(&self) -> usize {
31 self.data.len().saturating_sub(self.cursor)
32 }
33
34 pub fn is_empty(&self) -> bool {
36 self.len() == 0
37 }
38
39 pub fn reset(&mut self) {
41 self.cursor = 0;
42 }
43
44 pub fn total_len(&self) -> usize {
46 self.data.len()
47 }
48}
49
50impl<T: Clone> Iterator for NeoIterator<T> {
51 type Item = T;
52
53 fn next(&mut self) -> Option<T> {
54 if self.cursor >= self.data.len() {
55 None
56 } else {
57 let item = self.data[self.cursor].clone();
58 self.cursor += 1;
59 Some(item)
60 }
61 }
62
63 fn size_hint(&self) -> (usize, Option<usize>) {
64 let remaining = self.len();
65 (remaining, Some(remaining))
66 }
67}
68
69impl<T: Clone> ExactSizeIterator for NeoIterator<T> {}