1use crate::{Iter, PseudoFunc};
2use core::marker::PhantomData;
3
4#[derive(Debug, Clone, Copy)]
6struct DuplicateByCopying;
7
8impl<X: Copy> PseudoFunc<X, (X, X)> for DuplicateByCopying {
9 fn exec(x: X) -> (X, X) {
10 (x, x)
11 }
12}
13
14#[derive(Debug, Clone, Copy)]
16#[must_use = "iterators are lazy and do nothing unless consumed"]
17pub struct ScanCopy<Source, Compute, Value> {
18 internal: Iter<Source, DuplicateByCopying, Compute, Value, Value>,
19}
20
21impl<Source, Compute, Value> ScanCopy<Source, Compute, Value> {
22 pub(crate) fn new(source: Source, initial: Value, compute: Compute) -> Self {
23 let internal = Iter {
24 source,
25 compute,
26 state: initial,
27 _phantom: PhantomData,
28 };
29 ScanCopy { internal }
30 }
31}
32
33impl<Source, Compute, Value> Iterator for ScanCopy<Source, Compute, Value>
34where
35 Source: Iterator,
36 Compute: FnMut(Value, Source::Item) -> Value,
37 Value: Copy,
38{
39 type Item = Value;
40
41 fn next(&mut self) -> Option<Self::Item> {
42 self.internal.next()
43 }
44
45 fn size_hint(&self) -> (usize, Option<usize>) {
46 self.internal.size_hint()
47 }
48}