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