non_empty_iter/
inspect.rs1use 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 Inspect<I: NonEmptyIterator, F> {
16 non_empty: I,
17 function: F,
18}
19
20impl<I: NonEmptyIterator, F> Inspect<I, F> {
21 pub const fn new(non_empty: I, function: F) -> Self {
23 Self {
24 non_empty,
25 function,
26 }
27 }
28}
29
30impl<I: NonEmptyIterator, F: FnMut(&I::Item)> IntoIterator for Inspect<I, F> {
31 type Item = I::Item;
32
33 type IntoIter = iter::Inspect<I::IntoIter, F>;
34
35 fn into_iter(self) -> Self::IntoIter {
36 self.non_empty.into_iter().inspect(self.function)
37 }
38}
39
40unsafe impl<I: NonEmptyIterator, F: FnMut(&I::Item)> NonEmptyIterator for Inspect<I, F> {}