Base protocol refactor complete
parent: tbd commit: 079d544
1 | use ; |
2 | |
3 | use ; |
4 | use |
5 | , |
6 | , |
7 | , |
8 | , |
9 | ; |
10 | |
11 | use DatabaseBackend; |
12 | |
13 | |
14 | |
15 | O: GiteratedObject, |
16 | D: GiteratedOperation<O>, |
17 | S: Send + Sync + Clone, |
18 | > |
19 | |
20 | ; |
21 | ; |
22 | |
23 | async |
24 | &self, |
25 | object: &O, |
26 | operation: D, |
27 | state: S, |
28 | ; |
29 | |
30 | |
31 | |
32 | |
33 | |
34 | F: FnMut( |
35 | &O, |
36 | D, |
37 | S, |
38 | ) -> |
39 | , |
40 | > + Send |
41 | + Sync |
42 | + Clone, |
43 | O: GiteratedObject + Send + Sync, |
44 | D: + 'static, |
45 | : Send, | Failure
46 | S: Send + Sync + Clone + 'static, |
47 | |
48 | |
49 | operation_name |
50 | |
51 | |
52 | |
53 | object_name |
54 | |
55 | |
56 | async |
57 | &self, |
58 | object: &O, |
59 | operation: D, |
60 | state: S, |
61 | |
62 | self.clone .await |
63 | |
64 | |
65 | |
66 | |
67 | |
68 | dyn Fn( |
69 | AnyObject, |
70 | AnyOperation, |
71 | S, |
72 | ) |
73 | |
74 | + Send |
75 | + Sync, |
76 | >, |
77 | ); |
78 | |
79 | |
80 | |
81 | O: GiteratedObject + Send + Sync, |
82 | D: + 'static, |
83 | F: + Send + Sync + 'static + Clone, |
84 | > |
85 | handler: F, |
86 | |
87 | let handler = new; |
88 | Self |
89 | let handler = handler.clone; |
90 | async move |
91 | let handler = handler.clone; |
92 | let object: O = from_object_str .unwrap; |
93 | let operation: D = from_value .unwrap; |
94 | |
95 | let result = handler.handle .await; |
96 | result |
97 | .map |
98 | .map_err |
99 | => | Operation
100 | Operation |
101 | |
102 | => Internal, | Internal
103 | => Unhandled, | Unhandled
104 | |
105 | |
106 | .boxed |
107 | |
108 | |
109 | |
110 | async |
111 | &mut self, |
112 | object: AnyObject, |
113 | operation: AnyOperation, |
114 | state: S, |
115 | |
116 | self.0 .await |
117 | |
118 | |
119 | |
120 | |
121 | object: &User, |
122 | operation: , |
123 | state: DatabaseBackend, |
124 | |
125 | let object = object.clone; |
126 | |
127 | async move |
128 | let mut user_backend = state.user_backend.lock .await; |
129 | let value = user_backend |
130 | .get_value |
131 | .await |
132 | .map_err?; |
133 | |
134 | Ok |
135 | |
136 | .boxed |
137 | |
138 | |
139 | |
140 | object: &User, |
141 | operation: , |
142 | state: DatabaseBackend, |
143 | |
144 | let object = object.clone; |
145 | |
146 | async move |
147 | let mut user_backend = state.user_backend.lock .await; |
148 | let value = user_backend |
149 | .get_setting |
150 | .await |
151 | .map_err?; |
152 | |
153 | Ok |
154 | |
155 | .boxed |
156 | |
157 | |
158 | |
159 | object: &User, |
160 | operation: , |
161 | state: DatabaseBackend, |
162 | |
163 | let object = object.clone; |
164 | |
165 | async move |
166 | let mut user_backend = state.user_backend.lock .await; |
167 | let value = user_backend |
168 | .write_setting |
169 | .await |
170 | .map_err?; |
171 | |
172 | Ok |
173 | |
174 | .boxed |
175 | |
176 | |
177 | |
178 | object: &Repository, |
179 | operation: , |
180 | state: DatabaseBackend, |
181 | |
182 | let object = object.clone; |
183 | |
184 | async move |
185 | let mut repository_backend = state.repository_backend.lock .await; |
186 | let value = repository_backend |
187 | .get_value |
188 | .await |
189 | .map_err?; |
190 | |
191 | Ok |
192 | |
193 | .boxed |
194 | |
195 | |
196 | |
197 | object: &Repository, |
198 | operation: , |
199 | state: DatabaseBackend, |
200 | |
201 | let object = object.clone; |
202 | |
203 | async move |
204 | let mut repository_backend = state.repository_backend.lock .await; |
205 | let value = repository_backend |
206 | .get_setting |
207 | .await |
208 | .map_err?; |
209 | |
210 | Ok |
211 | |
212 | .boxed |
213 | |
214 | |
215 | |
216 | object: &Repository, |
217 | operation: , |
218 | state: DatabaseBackend, |
219 | |
220 | let object = object.clone; |
221 | |
222 | async move |
223 | let mut repository_backend = state.repository_backend.lock .await; |
224 | let value = repository_backend |
225 | .write_setting |
226 | .await |
227 | .map_err?; |
228 | |
229 | Ok |
230 | |
231 | .boxed |
232 | |
233 | |
234 | |
235 | operations: , |
236 | |
237 | |
238 | |
239 | |
240 | Self |
241 | operations: new, |
242 | |
243 | |
244 | |
245 | |
246 | |
247 | |
248 | O: GiteratedObject + Send + Sync, |
249 | D: + 'static, |
250 | H: + Send + Sync + 'static + Clone, |
251 | > |
252 | &mut self, |
253 | handler: H, |
254 | |
255 | let operation_name = handler.operation_name .to_string; |
256 | |
257 | let wrapped = new; |
258 | |
259 | self.operations.insert; |
260 | |
261 | self |
262 | |
263 | |
264 | pub async |
265 | &mut self, |
266 | object: &O, |
267 | operation_name: &str, |
268 | operation: AnyOperation, |
269 | state: S, |
270 | |
271 | if let Some = self.operations.get_mut |
272 | handler |
273 | .handle |
274 | .await |
275 | else |
276 | Err |
277 | "unknown operation: {}" |
278 | operation_name |
279 | ) |
280 | |
281 | |
282 | |
283 |