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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
// Datasouces are generator for data
//
// Datasources can be registered at Runtime
use ;
use AsyncFn1;
/// RuntimeDataSources are used to store data generated at runtime for Execution.
;
/// Async trait representing types that can modify a RuntimeDataStore.
/// Only the types that implement this trait can be added to an
/// [`Execution`](crate::logical::Execution) using
/// [`with_data`](crate::logical::Execution::with_data) method.
///
/// <div class="warning">
/// Because of the blanket implementation,
/// &T and &mut T does not implement this trait as it causes conflicting
/// implementation. So to share same data across multiple executor
/// it must be cloned. Another way of sharing same data modifier across
/// many executors is to use static/OnceLock inside the function definition.
/// </div>
///
/// ## Manual Implementaion
/// ```no_run
/// // Create a cheaply clonable type for using same data across execution.
/// #[derive(Clone)]
/// struct Def {
/// field: std::sync::Arc<usize>,
/// }
/// #[async_trait::async_trait]
/// impl DatastoreModifier for Def {
/// async fn init_store(&self, store: &mut RuntimeDataStore) {
/// store.insert(self.field.clone());
/// }
/// }
///
/// ```
/// Blanket implementation for `async fn(&mut RuntimeDataStore)`
/*
/// Implemented on Types that
pub trait Extractor<'a>: Sized {
fn from_runtime(runtime: &'a RuntimeDataStore) -> Result<Self, Error>;
}
impl<'a, T: 'static> Extractor<'a> for &'a T {
fn from_runtime(runtime: &'a RuntimeDataStore) -> Result<Self, Error> {
runtime
.get::<T>()
.ok_or_else(|| Error::termination("value not found in the datastore"))
}
}
macro_rules! impl_extractor {
{$($param:ident)*} => {
impl<'a, $($param,)*> Extractor<'a> for ($($param,)*)
where $($param: Extractor<'a>),*
{
#[allow(unused_variables)]
fn from_runtime(runtime: &'a RuntimeDataStore) -> Result<Self, Error> {
Ok(($($param::from_runtime(runtime)?,)*))
}
}
};
}
impl_extractor! {}
impl_extractor! { A }
impl_extractor! { A B }
impl_extractor! { A B C }
impl_extractor! { A B C D }
impl_extractor! { A B C D E }
impl_extractor! { A B C D E F }
impl_extractor! { A B C D E F G }
impl_extractor! { A B C D E F G H }
impl_extractor! { A B C D E F G H I }
impl_extractor! { A B C D E F G H I J }
impl_extractor! { A B C D E F G H I J K }
impl_extractor! { A B C D E F G H I J K L }
impl_extractor! { A B C D E F G H I J K L M }
impl_extractor! { A B C D E F G H I J K L M N }
impl_extractor! { A B C D E F G H I J K L M N O }
impl_extractor! { A B C D E F G H I J K L M N O P }
*/