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