Re-expose Operation State in generics.
This is the worst code I have ever written. I hate the way this changes everything. ugh.
parent: tbd commit: 90db3e2
1 | use ; |
2 | |
3 | use FutureExt; |
4 | use |
5 | , | OperationError
6 | , | Instance
7 | , |
8 | , | GiteratedOperation
9 | , | Setting
10 | , | GiteratedObjectValue
11 | ; |
12 | use ; |
13 | |
14 | use crate:: |
15 | , MetadataProvider, AnyFailure, AnyObject, AnyOperation, | HandlerWrapper
16 | AnySetting, AnySuccess, AnyValue, GiteratedStack, GiteratedStackState, IntoGiteratedHandler, |
17 | MaybeDynamicObject, MaybeDynamicValue, ObjectOperationPair, ObjectSettingPair, ObjectValuePair, |
18 | OperationHandler, OperationState, RuntimeMetadata, SettingChange, SettingGetter, |
19 | StackOperationState, ValueChange, ValueGetter, |
20 | ; |
21 | |
22 | |
23 | pub(crate) operation_handlers: , |
24 | pub(crate) value_getters: , |
25 | pub(crate) setting_getters: , |
26 | pub(crate) metadata: RuntimeMetadata, |
27 | pub(crate) value_change: , |
28 | pub(crate) metadata_providers: , |
29 | pub(crate) setting_change: , |
30 | |
31 | pub(crate) state: S, |
32 | _marker: , |
33 | |
34 | |
35 | |
36 | |
37 | Self |
38 | operation_handlers: Default default, |
39 | value_getters: Default default, |
40 | setting_getters: Default default, |
41 | metadata: Default default, |
42 | value_change: Default default, |
43 | metadata_providers: Default default, |
44 | setting_change: Default default, |
45 | state, |
46 | _marker: default, |
47 | |
48 | |
49 | |
50 | |
51 | |
52 | /// Insert an operation handler into the runtime builder. |
53 | /// |
54 | /// # Type Registration |
55 | /// Inserting the handler will automatically, if required, register the operation type of the |
56 | /// handler. It will **not** register the object type automatically. |
57 | |
58 | |
59 | O: GiteratedObject + Clone, |
60 | D: + Clone, |
61 | H: |
62 | + Send |
63 | + Sync |
64 | + 'static, |
65 | O: 'static, |
66 | D: 'static, |
67 | : Debug + 'static, | Failure
68 | : 'static, | Success
69 | OS: Clone, |
70 | |
71 | let wrapped = new; |
72 | |
73 | let wrapped = wrapped.map |
74 | |
75 | Ok |
76 | any_object.unwrap .clone, | .
77 | any_operation.unwrap .clone, | .
78 | |
79 | , |
80 | ; |
81 | |
82 | let wrapped = wrapped.map_return |
83 | Ok => Ok, |
84 | Err => Err |
85 | => | Operation
86 | Operation |
87 | |
88 | => Internal, | Internal
89 | => Unhandled, | Unhandled
90 | , |
91 | ; |
92 | |
93 | let pair = ; |
94 | |
95 | self.operation_handlers.insert; |
96 | |
97 | self.metadata.; |
98 | |
99 | self |
100 | |
101 | |
102 | /// Register a [`GiteratedObjectValue<O>`] type with the runtime, providing |
103 | /// its associated handler for [`GetValue`]. |
104 | /// |
105 | /// # Type Registration |
106 | /// This will register the provided [`GiteratedObjectValue`] type for its matching / specified |
107 | /// object type. It will **not** register the object type automatically. |
108 | |
109 | |
110 | O: MaybeDynamicObject + 'static, |
111 | F: |
112 | (O, String), |
113 | A, |
114 | S, |
115 | OS, |
116 | , |
117 | > + Send |
118 | + Sync, |
119 | F: 'static, |
120 | |
121 | let wrapped = new; |
122 | |
123 | let wrapped = wrapped.map |
124 | Ok |
125 | ; |
126 | |
127 | let wrapped = wrapped.map_return |
128 | Ok => Ok, |
129 | Err => Err |
130 | => Internal, | Operation
131 | => Internal, | Internal
132 | => Unhandled, | Unhandled
133 | , |
134 | ; |
135 | |
136 | assert! |
137 | .value_getters |
138 | .insert |
139 | ObjectValuePair |
140 | object_kind: object_name, |
141 | value_kind: "any" |
142 | , |
143 | wrapped |
144 | |
145 | .is_none; |
146 | |
147 | self |
148 | |
149 | |
150 | |
151 | |
152 | F: |
153 | + Send |
154 | + Sync, |
155 | V: MaybeDynamicValue + Clone + 'static, |
156 | O: 'static + MaybeDynamicObject, |
157 | V: 'static, |
158 | F: 'static, |
159 | |
160 | let wrapped = new; |
161 | |
162 | let wrapped = wrapped.map |
163 | |
164 | Ok |
165 | , |
166 | ; |
167 | |
168 | assert! |
169 | .value_change |
170 | .insert |
171 | ObjectValuePair |
172 | object_kind: object_name, |
173 | value_kind: value_name |
174 | , |
175 | wrapped |
176 | |
177 | .is_none; |
178 | |
179 | self |
180 | |
181 | |
182 | |
183 | self.metadata_providers.push; |
184 | |
185 | self |
186 | |
187 | |
188 | |
189 | |
190 | /// Register a [`GiteratedObject`] type with the runtime. |
191 | /// |
192 | /// # Type Registration |
193 | /// This will register the provided object type. |
194 | |
195 | self.metadata.; |
196 | |
197 | // Insert handler so ObjectRequest is handled properly |
198 | |
199 | self.operation |
200 | move |_object: Instance, |
201 | operation: ObjectRequest, |
202 | _state: S, |
203 | stack: | |
204 | let operation = operation.clone; |
205 | async move |
206 | for in stack.inner.metadata.objects.iter |
207 | if .is_ok |
208 | return Ok; |
209 | |
210 | |
211 | |
212 | Err |
213 | |
214 | .boxed_local |
215 | , |
216 | ; |
217 | |
218 | self |
219 | |
220 | |
221 | /// Register a [`Setting`] type with the runtime. |
222 | /// |
223 | /// # Type Registration |
224 | /// This will register the provided setting type. |
225 | |
226 | &mut self, |
227 | |
228 | self.metadata.; |
229 | |
230 | self |
231 | |
232 | |
233 | /// Register a [`GiteratedObjectValue`] that is also a [`Setting`], which |
234 | /// allows for automatic value updates. |
235 | |
236 | O: GiteratedObject + 'static + Clone, |
237 | T: + Setting + 'static + Clone, |
238 | > |
239 | &mut self, |
240 | |
241 | self.metadata.; |
242 | self.metadata.; |
243 | |
244 | self.setting_change.insert |
245 | , |
246 | new |
247 | , |
248 | move |object: AnyObject, |
249 | setting: AnySetting, |
250 | _state: _, |
251 | OperationState: , |
252 | stack: | |
253 | trace! |
254 | "value setting updated {}::{}", |
255 | , | object_name
256 | value_name |
257 | ; |
258 | let object = object.clone; |
259 | async move |
260 | let object = object. .unwrap; |
261 | let setting = setting. .unwrap; |
262 | stack |
263 | .value_update |
264 | object.clone, |
265 | , | new
266 | &operation_state, |
267 | |
268 | .await; |
269 | Ok |
270 | |
271 | .boxed_local |
272 | , |
273 | , |
274 | ; |
275 | |
276 | let wrapped = new |
277 | self.state.clone, |
278 | |
279 | |
280 | _state: _, |
281 | stack: | |
282 | info!; |
283 | let object = object.clone; |
284 | async move |
285 | match stack |
286 | . |
287 | .await |
288 | |
289 | Ok => Ok, |
290 | Err => |
291 | panic!; |
292 | |
293 | |
294 | |
295 | .boxed_local |
296 | , |
297 | ; |
298 | |
299 | self.value_getters |
300 | .insert; |
301 | |
302 | self |
303 | |
304 | |
305 | |
306 | // Placeholder |
307 | |
308 | |
309 | !; | error
310 | |
311 | self |
312 | |
313 | |
314 | |
315 | |
316 | ; |
317 |