Finish unified stack refactor.
Adds support for operation state, which will be used to pass authentication information around. Added generic backend that uses a channel to communicate with a typed backend.
parent: tbd commit: d15581c
1 | use |
2 | , | OperationError
3 | |
4 | AnyObject, GiteratedObject, Object, ObjectRequest, ObjectRequestError, ObjectResponse, |
5 | , |
6 | , | ObjectBackend
7 | , |
8 | ; |
9 | use ; |
10 | use warn; |
11 | |
12 | use crate::; |
13 | |
14 | use crate StackOperationState; |
15 | |
16 | |
17 | |
18 | state: S, |
19 | handlers: , |
20 | |
21 | |
22 | |
23 | |
24 | Self |
25 | state, |
26 | handlers: new, |
27 | |
28 | |
29 | |
30 | |
31 | &self.state |
32 | |
33 | |
34 | |
35 | |
36 | |
37 | async |
38 | &self, |
39 | object: O, |
40 | operation: &str, |
41 | payload: D, |
42 | operation_state: &StackOperationState, |
43 | |
44 | |
45 | O: GiteratedObject + Debug, |
46 | D: + Debug, |
47 | |
48 | let serialized = |
49 | map_err?; | to_value .
50 | let object = object.to_string; |
51 | |
52 | if operation == operation_name |
53 | // We're doing an object request |
54 | let raw_result = self |
55 | .handlers |
56 | .resolve_object |
57 | AnyObject, |
58 | unwrap, | from_value .
59 | self.state.clone, |
60 | &operation_state, |
61 | |
62 | .await; |
63 | |
64 | return match raw_result |
65 | Ok => Ok |
66 | .map_err?, |
67 | Err => match err |
68 | => | Internal
69 | warn! |
70 | "Internal Error: {:?}", |
71 | Internal |
72 | ; |
73 | |
74 | Err |
75 | |
76 | => Err, | Unhandled
77 | => Err | Operation
78 | from_slice |
79 | .map_err?, |
80 | , |
81 | , |
82 | ; |
83 | |
84 | |
85 | let raw_result = self |
86 | .handlers |
87 | .handle |
88 | &AnyObject, |
89 | operation, |
90 | AnyOperation, |
91 | self.state.clone, |
92 | &operation_state, |
93 | |
94 | .await; |
95 | |
96 | match raw_result |
97 | Ok => Ok |
98 | .map_err?, |
99 | Err => match err |
100 | => | Internal
101 | warn! |
102 | "Internal Error: {:?}", |
103 | Internal |
104 | ; |
105 | |
106 | Err |
107 | |
108 | => Err, | Unhandled
109 | => Err | Operation
110 | from_slice |
111 | .map_err?, |
112 | , |
113 | , |
114 | |
115 | |
116 | |
117 | async |
118 | &self, |
119 | object_str: &str, |
120 | operation_state: &StackOperationState, |
121 | |
122 | let raw_result = self |
123 | .handlers |
124 | .resolve_object |
125 | AnyObject, |
126 | ObjectRequest, |
127 | self.state.clone, |
128 | operation_state, |
129 | |
130 | .await; |
131 | |
132 | let object: ObjectResponse = match raw_result |
133 | Ok => Ok |
134 | .map_err?, |
135 | Err => match err |
136 | => | Internal
137 | warn! |
138 | "Internal Error: {:?}", |
139 | Internal |
140 | ; |
141 | |
142 | Err |
143 | |
144 | => Err, | Unhandled
145 | => Err | Operation
146 | from_slice |
147 | .map_err?, |
148 | , |
149 | , |
150 | ?; |
151 | |
152 | unsafe |
153 | Ok |
154 | from_str |
155 | .map_err?, |
156 | self.clone, |
157 | |
158 | |
159 | |
160 | |
161 |