1use core::iter;
4
5use crate::non_empty::NonEmptyIterator;
6
7pub struct Cycle<I: NonEmptyIterator>
14where
15 I::IntoIter: Clone,
16{
17 non_empty: I,
18}
19
20impl<I: NonEmptyIterator> Cycle<I>
21where
22 I::IntoIter: Clone,
23{
24 pub const fn new(non_empty: I) -> Self {
26 Self { non_empty }
27 }
28}
29
30impl<I: NonEmptyIterator> IntoIterator for Cycle<I>
31where
32 I::IntoIter: Clone,
33{
34 type Item = I::Item;
35
36 type IntoIter = iter::Cycle<I::IntoIter>;
37
38 fn into_iter(self) -> Self::IntoIter {
39 self.non_empty.into_iter().cycle()
40 }
41}
42
43unsafe impl<I: NonEmptyIterator> NonEmptyIterator for Cycle<I> where I::IntoIter: Clone {}