1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
use crate::ExchangeData;
use crate::dataflow::channels::pact::Exchange as ExchangePact;
use crate::dataflow::{Stream, Scope};
use crate::dataflow::operators::generic::operator::Operator;
pub trait Exchange<T, D: ExchangeData> {
fn exchange(&self, route: impl Fn(&D)->u64+'static) -> Self;
}
impl<G: Scope, D: ExchangeData> Exchange<G::Timestamp, D> for Stream<G, D> {
fn exchange(&self, route: impl Fn(&D)->u64+'static) -> Stream<G, D> {
let mut vector = Vec::new();
self.unary(ExchangePact::new(route), "Exchange", move |_,_| move |input, output| {
input.for_each(|time, data| {
data.swap(&mut vector);
output.session(&time).give_vec(&mut vector);
});
})
}
}