standing_relations/core/op/
dynamic.rs1use crate::core::{
2 relation::{self, RelationInner},
3 Op_, Relation,
4};
5
6pub struct Dynamic<'a, T>(Box<RelationInner<dyn DynOp<T = T> + 'a>>);
7
8impl<'b, T> Op_ for Dynamic<'b, T> {
9 type T = T;
10
11 fn foreach<'a>(&'a mut self, continuation: impl FnMut(Self::T) + 'a) {
12 self.0.inner.foreach(Box::new(relation::with_counter(
13 &mut self.0.counter,
14 continuation,
15 )))
16 }
17
18 fn get_type_name() -> &'static str {
19 "dynamic"
20 }
21}
22
23trait DynOp {
24 type T;
25
26 fn foreach<'a>(&'a mut self, continuation: Box<dyn FnMut(Self::T) + 'a>);
27}
28
29impl<C: Op_> DynOp for C {
30 type T = C::T;
31
32 fn foreach<'a>(&'a mut self, continuation: Box<dyn FnMut(Self::T) + 'a>) {
33 Op_::foreach(self, continuation)
34 }
35}
36
37impl<C: Op_> Relation<C> {
38 pub fn dynamic_shown<'a>(self) -> Relation<Dynamic<'a, C::T>>
39 where
40 C: 'a,
41 {
42 self.context_tracker.add_relation(
43 self.dirty,
44 Dynamic(Box::new(self.inner)),
45 vec![self.tracking_index],
46 )
47 }
48}