use std::iter::{DoubleEndedIterator, FusedIterator};
use crate::{listiter::ListIter, IndexList};
pub struct ListDrainIter<'a, T>(&'a mut IndexList<T>);
impl<'a, T> ListDrainIter<'a, T> {
pub fn new(list: &'a mut IndexList<T>) -> Self {
ListDrainIter::<'a, T>(list)
}
}
impl<'a, T> Iterator for ListDrainIter<'a, T> {
type Item = T;
fn next(&mut self) -> Option<Self::Item> {
self.0.remove_first()
}
}
impl<'a, T> DoubleEndedIterator for ListDrainIter<'a, T> {
fn next_back(&mut self) -> Option<Self::Item> {
self.0.remove_last()
}
}
impl<T> FusedIterator for ListDrainIter<'_, T> {}
impl<'a, T> IntoIterator for &'a IndexList<T> {
type Item = &'a T;
type IntoIter = ListIter<'a, T>;
fn into_iter(self) -> Self::IntoIter {
self.iter()
}
}