1use core::iter;
4
5use crate::non_empty::NonEmptyIterator;
6
7#[derive(Debug, Clone)]
14#[must_use = "non-empty iterators are lazy and do nothing unless consumed"]
15pub struct Cloned<I: NonEmptyIterator> {
16 non_empty: I,
17}
18
19impl<I: NonEmptyIterator> Cloned<I> {
20 pub const fn new(non_empty: I) -> Self {
22 Self { non_empty }
23 }
24}
25
26impl<'a, I, T> IntoIterator for Cloned<I>
27where
28 I: NonEmptyIterator<Item = &'a T>,
29 T: Clone + 'a,
30{
31 type Item = T;
32
33 type IntoIter = iter::Cloned<I::IntoIter>;
34
35 fn into_iter(self) -> Self::IntoIter {
36 self.non_empty.into_iter().cloned()
37 }
38}
39
40unsafe impl<'a, I, T> NonEmptyIterator for Cloned<I>
41where
42 I: NonEmptyIterator<Item = &'a T>,
43 T: Clone + 'a,
44{
45}