#[cfg(feature = "alloc")]
use crate::alloc;
use core::{alloc::Allocator, iter::FusedIterator};
use crate::DynList;
pub struct IntoIter<
T,
#[cfg(feature = "alloc")] A = alloc::Global,
#[cfg(not(feature = "alloc"))] A,
> where
A: Allocator,
{
list: DynList<T, A>,
}
impl<T, A> IntoIter<T, A>
where
A: Allocator,
{
#[must_use]
#[inline]
pub(crate) const fn new(list: DynList<T, A>) -> Self {
Self { list }
}
#[must_use]
#[inline]
pub const fn remainder(&self) -> &DynList<T, A> {
&self.list
}
#[must_use]
#[inline]
pub fn take_remainder(self) -> DynList<T, A> {
self.list
}
}
#[cfg(feature = "alloc")]
impl<T> Default for IntoIter<T> {
#[inline]
fn default() -> Self {
Self::new(DynList::default())
}
}
impl<T, A> Iterator for IntoIter<T, A>
where
A: Allocator,
{
type Item = T;
fn next(&mut self) -> Option<Self::Item> {
self.list.pop_front()
}
}
impl<T, A> DoubleEndedIterator for IntoIter<T, A>
where
A: Allocator,
{
fn next_back(&mut self) -> Option<Self::Item> {
self.list.pop_back()
}
}
impl<T, A> FusedIterator for IntoIter<T, A> where A: Allocator {}
impl<T, A> IntoIterator for DynList<T, A>
where
A: Allocator,
{
type Item = T;
type IntoIter = IntoIter<T, A>;
fn into_iter(self) -> Self::IntoIter {
IntoIter::new(self)
}
}