use core::iter;
use crate::non_empty::NonEmptyIterator;
pub struct Cycle<I: NonEmptyIterator>
where
I::IntoIter: Clone,
{
non_empty: I,
}
impl<I: NonEmptyIterator> Cycle<I>
where
I::IntoIter: Clone,
{
pub const fn new(non_empty: I) -> Self {
Self { non_empty }
}
}
impl<I: NonEmptyIterator> IntoIterator for Cycle<I>
where
I::IntoIter: Clone,
{
type Item = I::Item;
type IntoIter = iter::Cycle<I::IntoIter>;
fn into_iter(self) -> Self::IntoIter {
self.non_empty.into_iter().cycle()
}
}
unsafe impl<I: NonEmptyIterator> NonEmptyIterator for Cycle<I> where I::IntoIter: Clone {}