1use core::iter;
4
5use non_zero_size::Size;
6
7use crate::non_empty::NonEmptyIterator;
8
9#[derive(Debug, Clone)]
12#[must_use = "non-empty iterators are lazy and do nothing unless consumed"]
13pub struct Take<I: NonEmptyIterator> {
14 non_empty: I,
15 count: Size,
16}
17
18impl<I: NonEmptyIterator> Take<I> {
19 pub const fn new(non_empty: I, count: Size) -> Self {
21 Self { non_empty, count }
22 }
23}
24
25impl<I: NonEmptyIterator> IntoIterator for Take<I> {
26 type Item = I::Item;
27
28 type IntoIter = iter::Take<I::IntoIter>;
29
30 fn into_iter(self) -> Self::IntoIter {
31 self.non_empty.into_iter().take(self.count.get())
32 }
33}
34
35unsafe impl<I: NonEmptyIterator> NonEmptyIterator for Take<I> {}