JavaScript is disabled, refresh for a better experience. ambee/giterated

ambee/giterated

Git repository hosting, collaboration, and discovery for the Fediverse.

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

Amber - ⁨2⁩ years ago

parent: tbd commit: ⁨90c4780

⁨giterated-stack/src/handler/handler_impl.rs⁩ - ⁨8585⁩ bytes
Raw
1 use futures_util::Future;
2 use giterated_models::error::OperationError;
3
4 use crate::{HandlerResolvable, IntoGiteratedHandler};
5
6 #[async_trait::async_trait(?Send)]
7 impl<R1, S, OS, Success, Failure, H, Fut>
8 IntoGiteratedHandler<(R1,), (), S, OS, Result<Success, OperationError<Failure>>> for H
9 where
10 H: FnMut(R1, S, OS) -> Fut + Clone,
11 Fut: Future<Output = Result<Success, OperationError<Failure>>> + 'static,
12 Success: 'static,
13 Failure: 'static,
14 R1: 'static,
15 S: 'static,
16 OS: 'static,
17 {
18 type Future = Fut;
19
20 async fn handle(
21 &self,
22 parameters: (R1,),
23 state: S,
24 operation_state: OS,
25 ) -> Result<Success, OperationError<Failure>> {
26 let (r1,) = parameters;
27 (self.clone())(r1, state, operation_state).await
28 }
29 }
30
31 #[async_trait::async_trait(?Send)]
32 impl<R1, A1, S, OS, Success, Failure, H, Fut>
33 IntoGiteratedHandler<(R1,), (A1,), S, OS, Result<Success, OperationError<Failure>>> for H
34 where
35 H: FnMut(R1, S, OS, A1) -> Fut + Clone,
36 Fut: Future<Output = Result<Success, OperationError<Failure>>> + 'static,
37 Success: 'static,
38 Failure: 'static,
39 R1: 'static,
40 S: 'static,
41 OS: 'static,
42 A1: HandlerResolvable<(R1,), OS>,
43 A1::Error: Into<anyhow::Error>,
44 {
45 type Future = Fut;
46
47 async fn handle(
48 &self,
49 parameters: (R1,),
50 state: S,
51 operation_state: OS,
52 ) -> Result<Success, OperationError<Failure>> {
53 let a1 = A1::from_handler_state(&parameters, &operation_state)
54 .await
55 .map_err(|e| OperationError::Internal(e.into()))?;
56 let (r1,) = parameters;
57 (self.clone())(r1, state, operation_state, a1).await
58 }
59 }
60
61 #[async_trait::async_trait(?Send)]
62 impl<R1, A1, A2, S, OS, Success, Failure, H, Fut>
63 IntoGiteratedHandler<(R1,), (A1, A2), S, OS, Result<Success, OperationError<Failure>>> for H
64 where
65 H: FnMut(R1, S, OS, A1, A2) -> Fut + Clone,
66 Fut: Future<Output = Result<Success, OperationError<Failure>>> + 'static,
67 Success: 'static,
68 Failure: 'static,
69 R1: 'static,
70 S: 'static,
71 OS: 'static,
72 A1: HandlerResolvable<(R1,), OS>,
73 A1::Error: Into<anyhow::Error>,
74 A2: HandlerResolvable<(R1,), OS>,
75 A2::Error: Into<anyhow::Error>,
76 {
77 type Future = Fut;
78
79 async fn handle(
80 &self,
81 parameters: (R1,),
82 state: S,
83 operation_state: OS,
84 ) -> Result<Success, OperationError<Failure>> {
85 let a1 = A1::from_handler_state(&parameters, &operation_state)
86 .await
87 .map_err(|e| OperationError::Internal(e.into()))?;
88 let a2 = A2::from_handler_state(&parameters, &operation_state)
89 .await
90 .map_err(|e| OperationError::Internal(e.into()))?;
91 let (r1,) = parameters;
92 (self.clone())(r1, state, operation_state, a1, a2).await
93 }
94 }
95
96 #[async_trait::async_trait(?Send)]
97 impl<R1, A1, A2, A3, S, OS, Success, Failure, H, Fut>
98 IntoGiteratedHandler<(R1,), (A1, A2, A3), S, OS, Result<Success, OperationError<Failure>>> for H
99 where
100 H: FnMut(R1, S, OS, A1, A2, A3) -> Fut + Clone,
101 Fut: Future<Output = Result<Success, OperationError<Failure>>> + 'static,
102 Success: 'static,
103 Failure: 'static,
104 R1: 'static,
105 S: 'static,
106 OS: 'static,
107 A1: HandlerResolvable<(R1,), OS>,
108 A1::Error: Into<anyhow::Error>,
109 A2: HandlerResolvable<(R1,), OS>,
110 A2::Error: Into<anyhow::Error>,
111 A3: HandlerResolvable<(R1,), OS>,
112 A3::Error: Into<anyhow::Error>,
113 {
114 type Future = Fut;
115
116 async fn handle(
117 &self,
118 parameters: (R1,),
119 state: S,
120 operation_state: OS,
121 ) -> Result<Success, OperationError<Failure>> {
122 let a1 = A1::from_handler_state(&parameters, &operation_state)
123 .await
124 .map_err(|e| OperationError::Internal(e.into()))?;
125 let a2 = A2::from_handler_state(&parameters, &operation_state)
126 .await
127 .map_err(|e| OperationError::Internal(e.into()))?;
128 let a3 = A3::from_handler_state(&parameters, &operation_state)
129 .await
130 .map_err(|e| OperationError::Internal(e.into()))?;
131 let (r1,) = parameters;
132 (self.clone())(r1, state, operation_state, a1, a2, a3).await
133 }
134 }
135
136 #[async_trait::async_trait(?Send)]
137 impl<R1, R2, S, OS, Success, Failure, H, Fut>
138 IntoGiteratedHandler<(R1, R2), (), S, OS, Result<Success, OperationError<Failure>>> for H
139 where
140 H: FnMut(R1, R2, S, OS) -> Fut + Clone,
141 Fut: Future<Output = Result<Success, OperationError<Failure>>> + 'static,
142 Success: 'static,
143 Failure: 'static,
144 R1: 'static,
145 R2: 'static,
146 S: 'static,
147 OS: 'static,
148 {
149 type Future = Fut;
150
151 async fn handle(
152 &self,
153 parameters: (R1, R2),
154 state: S,
155 operation_state: OS,
156 ) -> Result<Success, OperationError<Failure>> {
157 let (r1, r2) = parameters;
158 (self.clone())(r1, r2, state, operation_state).await
159 }
160 }
161
162 #[async_trait::async_trait(?Send)]
163 impl<R1, R2, A1, S, OS, Success, Failure, H, Fut>
164 IntoGiteratedHandler<(R1, R2), (A1,), S, OS, Result<Success, OperationError<Failure>>> for H
165 where
166 H: FnMut(R1, R2, S, OS, A1) -> Fut + Clone,
167 Fut: Future<Output = Result<Success, OperationError<Failure>>> + 'static,
168 Success: 'static,
169 Failure: 'static,
170 R1: 'static,
171 R2: 'static,
172 S: 'static,
173 OS: 'static,
174 A1: HandlerResolvable<(R1, R2), OS>,
175 A1::Error: Into<anyhow::Error>,
176 {
177 type Future = Fut;
178
179 async fn handle(
180 &self,
181 parameters: (R1, R2),
182 state: S,
183 operation_state: OS,
184 ) -> Result<Success, OperationError<Failure>> {
185 let a1 = A1::from_handler_state(&parameters, &operation_state)
186 .await
187 .map_err(|e| OperationError::Internal(e.into()))?;
188
189 let (r1, r2) = parameters;
190 (self.clone())(r1, r2, state, operation_state, a1).await
191 }
192 }
193
194 #[async_trait::async_trait(?Send)]
195 impl<R1, R2, A1, A2, S, OS, Success, Failure, H, Fut>
196 IntoGiteratedHandler<(R1, R2), (A1, A2), S, OS, Result<Success, OperationError<Failure>>> for H
197 where
198 H: FnMut(R1, R2, S, OS, A1, A2) -> Fut + Clone,
199 Fut: Future<Output = Result<Success, OperationError<Failure>>> + 'static,
200 Success: 'static,
201 Failure: 'static,
202 R1: 'static,
203 R2: 'static,
204 S: 'static,
205 OS: 'static,
206 A1: HandlerResolvable<(R1, R2), OS>,
207 A1::Error: Into<anyhow::Error>,
208 A2: HandlerResolvable<(R1, R2), OS>,
209 A2::Error: Into<anyhow::Error>,
210 {
211 type Future = Fut;
212
213 async fn handle(
214 &self,
215 parameters: (R1, R2),
216 state: S,
217 operation_state: OS,
218 ) -> Result<Success, OperationError<Failure>> {
219 let a1 = A1::from_handler_state(&parameters, &operation_state)
220 .await
221 .map_err(|e| OperationError::Internal(e.into()))?;
222 let a2 = A2::from_handler_state(&parameters, &operation_state)
223 .await
224 .map_err(|e| OperationError::Internal(e.into()))?;
225
226 let (r1, r2) = parameters;
227 (self.clone())(r1, r2, state, operation_state, a1, a2).await
228 }
229 }
230
231 #[async_trait::async_trait(?Send)]
232 impl<R1, R2, A1, A2, A3, S, OS, Success, Failure, H, Fut>
233 IntoGiteratedHandler<(R1, R2), (A1, A2, A3), S, OS, Result<Success, OperationError<Failure>>>
234 for H
235 where
236 H: FnMut(R1, R2, S, OS, A1, A2, A3) -> Fut + Clone,
237 Fut: Future<Output = Result<Success, OperationError<Failure>>> + 'static,
238 Success: 'static,
239 Failure: 'static,
240 R1: 'static,
241 R2: 'static,
242 S: 'static,
243 OS: 'static,
244 A1: HandlerResolvable<(R1, R2), OS>,
245 A1::Error: Into<anyhow::Error>,
246 A2: HandlerResolvable<(R1, R2), OS>,
247 A2::Error: Into<anyhow::Error>,
248 A3: HandlerResolvable<(R1, R2), OS>,
249 A3::Error: Into<anyhow::Error>,
250 {
251 type Future = Fut;
252
253 async fn handle(
254 &self,
255 parameters: (R1, R2),
256 state: S,
257 operation_state: OS,
258 ) -> Result<Success, OperationError<Failure>> {
259 let a1 = A1::from_handler_state(&parameters, &operation_state)
260 .await
261 .map_err(|e| OperationError::Internal(e.into()))?;
262 let a2 = A2::from_handler_state(&parameters, &operation_state)
263 .await
264 .map_err(|e| OperationError::Internal(e.into()))?;
265 let a3 = A3::from_handler_state(&parameters, &operation_state)
266 .await
267 .map_err(|e| OperationError::Internal(e.into()))?;
268
269 let (r1, r2) = parameters;
270 (self.clone())(r1, r2, state, operation_state, a1, a2, a3).await
271 }
272 }
273