use std::vec::Vec;
#[derive(Debug, Clone)]
pub struct NeoIterator<T> {
data: Vec<T>,
cursor: usize,
}
impl<T> NeoIterator<T> {
pub fn new(data: Vec<T>) -> Self {
Self { data, cursor: 0 }
}
pub fn has_next(&self) -> bool {
self.cursor < self.data.len()
}
pub fn len(&self) -> usize {
self.data.len().saturating_sub(self.cursor)
}
pub fn is_empty(&self) -> bool {
self.len() == 0
}
pub fn reset(&mut self) {
self.cursor = 0;
}
pub fn total_len(&self) -> usize {
self.data.len()
}
}
impl<T: Clone> Iterator for NeoIterator<T> {
type Item = T;
fn next(&mut self) -> Option<T> {
if self.cursor >= self.data.len() {
None
} else {
let item = self.data[self.cursor].clone();
self.cursor += 1;
Some(item)
}
}
fn size_hint(&self) -> (usize, Option<usize>) {
let remaining = self.len();
(remaining, Some(remaining))
}
}
impl<T: Clone> ExactSizeIterator for NeoIterator<T> {}