Beginning of `stack-next` refactor
-Refactoring the protocol stack into something similar to a runtime. -Handles merging handler builders which is placing the ground work for plugins in. - Increased metadata generation during compilation enables less ser/de during execution. - Goal is to have an O(1) time from incoming operation to calling handlers. - Decreased penalty for using the statically typed API from within your code, now avoids some allocation. # Changes - Added `GiteratedRuntime` which is to replace the current unified stack - Added `RuntimeBuilder` which does what the current `OperationHandlers` struct does, but much better. - Added `RuntimeMetadata` to store type metadata for new `Any` based internals - Refactored serde_json out of the internal operation handling
parent: tbd commit: 708dea4
1 | use |
2 | , | OperationError
3 | , | Instance
4 | |
5 | AnyObject, GiteratedObject, Object, ObjectRequest, ObjectRequestError, ObjectResponse, |
6 | , |
7 | , | ObjectBackend
8 | , |
9 | ; |
10 | use ; |
11 | use Mutex; |
12 | use warn; |
13 | |
14 | use crate:: |
15 | , | HandlerState
16 | , |
17 | OperationHandlers, |
18 | ; |
19 | |
20 | use crate StackOperationState; |
21 | |
22 | |
23 | |
24 | state: S, |
25 | handlers: , |
26 | |
27 | |
28 | |
29 | |
30 | Self |
31 | state, |
32 | handlers: new, |
33 | |
34 | |
35 | |
36 | |
37 | &self.state |
38 | |
39 | |
40 | |
41 | |
42 | |
43 | async |
44 | &self, |
45 | object: O, |
46 | operation: &str, |
47 | payload: D, |
48 | operation_state: &StackOperationState, |
49 | |
50 | |
51 | O: GiteratedObject + Debug + 'static, |
52 | D: + Debug, |
53 | |
54 | let serialized = |
55 | map_err?; | to_value .
56 | let object = |
57 | . |
58 | .unwrap; |
59 | |
60 | if operation == operation_name |
61 | // We're doing an object request |
62 | let raw_result = self |
63 | .handlers |
64 | .resolve_object |
65 | * |
66 | .downcast |
67 | .unwrap, |
68 | unwrap, | from_value .
69 | self.state.clone, |
70 | &operation_state, |
71 | |
72 | .await; |
73 | |
74 | return match raw_result |
75 | Ok => Ok |
76 | .map_err?, |
77 | Err => match err |
78 | => | Internal
79 | warn! |
80 | "Internal Error: {:?}", |
81 | Internal |
82 | ; |
83 | |
84 | Err |
85 | |
86 | => Err, | Unhandled
87 | => Err | Operation
88 | from_slice |
89 | .map_err?, |
90 | , |
91 | , |
92 | ; |
93 | |
94 | |
95 | let raw_result = self |
96 | .handlers |
97 | .handle |
98 | &*object, |
99 | operation, |
100 | AnyOperation, |
101 | self.state.clone, |
102 | &operation_state, |
103 | |
104 | .await; |
105 | |
106 | match raw_result |
107 | Ok => Ok |
108 | .map_err?, |
109 | Err => match err |
110 | => | Internal
111 | warn! |
112 | "Internal Error: {:?}", |
113 | Internal |
114 | ; |
115 | |
116 | Err |
117 | |
118 | => Err, | Unhandled
119 | => Err | Operation
120 | from_slice |
121 | .map_err?, |
122 | , |
123 | , |
124 | |
125 | |
126 | |
127 | async |
128 | &self, |
129 | object_str: &str, |
130 | operation_state: &StackOperationState, |
131 | |
132 | let raw_result = self |
133 | .handlers |
134 | .resolve_object |
135 | unwrap, | from_str .
136 | ObjectRequest, |
137 | self.state.clone, |
138 | operation_state, |
139 | |
140 | .await; |
141 | |
142 | let object: ObjectResponse = match raw_result |
143 | Ok => Ok |
144 | .map_err?, |
145 | Err => match err |
146 | => | Internal
147 | warn! |
148 | "Internal Error: {:?}", |
149 | Internal |
150 | ; |
151 | |
152 | Err |
153 | |
154 | => Err, | Unhandled
155 | => Err | Operation
156 | from_slice |
157 | .map_err?, |
158 | , |
159 | , |
160 | ?; |
161 | |
162 | unsafe |
163 | Ok |
164 | from_str |
165 | .map_err?, |
166 | self.clone, |
167 | |
168 | |
169 | |
170 | |
171 |