substreams/
operation.rs

1use crate::{pb::substreams::store_delta::Operation, store::Delta};
2
3pub struct OperationIs<I: Iterator> {
4    operation: Operation,
5    negate: bool,
6    underlying: I,
7}
8
9impl<I> OperationIs<I>
10where
11    I: Iterator,
12    I::Item: Delta,
13{
14    pub(crate) fn new(operation: Operation, negate: bool, underlying: I) -> Self {
15        Self {
16            operation,
17            negate,
18            underlying,
19        }
20    }
21}
22
23impl<I> Iterator for OperationIs<I>
24where
25    I: Iterator,
26    I::Item: Delta,
27{
28    type Item = I::Item;
29
30    fn next(&mut self) -> Option<Self::Item> {
31        while let Some(x) = self.underlying.next() {
32            let mut emit = x.get_operation() == self.operation;
33            if self.negate {
34                emit = !emit;
35            }
36
37            if emit {
38                return Some(x);
39            }
40        }
41
42        None
43    }
44}