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-cache/src/cache_update.rs⁩ - ⁨10461⁩ bytes
Raw
1 // use std::{any::Any, pin::Pin, process::Output, sync::Arc};
2
3 // use futures_util::{future::LocalBoxFuture, Future, FutureExt};
4 // use giterated_models::{
5 // error::{ExtractorError, OperationError, RepositoryError},
6 // object::GiteratedObject,
7 // operation::GiteratedOperation,
8 // repository::{Repository, RepositoryBranch, RepositoryBranchesRequest},
9 // settings::SetSetting,
10 // user::{DisplayName, User},
11 // value::{GetValue, GiteratedObjectValue},
12 // };
13 // use giterated_stack::{
14 // AuthorizedUser, FromOperationState, GiteratedStack, MissingValue, StackOperationState,
15 // };
16
17 // use crate::CacheSubstack;
18
19 // async fn value_update(
20 // object: AnyObject<'_>,
21 // value: AnyValue<'_>,
22 // cache: CacheSubstack,
23 // stack: Arc<GiteratedStack>,
24 // ) -> Result<(), anyhow::Error> {
25 // todo!()
26 // }
27
28 // pub struct AnyObject<'o>(&'o (dyn Any + Send + Sync));
29
30 // pub struct AnyValue<'v>(&'v (dyn Any + Send + Sync));
31
32 // #[async_trait::async_trait(?Send)]
33 // pub trait GiteratedHandler<RequiredParameters, AdditionalParameters, State, OperationState, Output>
34 // {
35 // async fn handle(
36 // &self,
37 // parameters: RequiredParameters,
38 // additional_parameters: AdditionalParameters,
39 // state: Arc<State>,
40 // operation_state: &OperationState,
41 // ) -> Output;
42 // }
43
44 // #[async_trait::async_trait(?Send)]
45 // impl<R1, S, O, Output, F, Fut> GiteratedHandler<(R1,), (), S, O, Output> for F
46 // where
47 // F: FnMut(R1, S, &O) -> Fut,
48 // Fut: Future<Output = Output>,
49 // S: 'static,
50 // R1: 'static,
51 // {
52 // async fn handle(
53 // &self,
54 // parameters: (R1,),
55 // additional_parameters: (),
56 // state: Arc<S>,
57 // operation_state: &O,
58 // ) -> Output {
59 // todo!()
60 // }
61 // }
62
63 // #[async_trait::async_trait(?Send)]
64 // impl<R1, A1, S, O, Output, F, Fut> GiteratedHandler<(R1,), (A1,), S, O, Output> for F
65 // where
66 // F: FnMut(R1, S, &O, A1) -> Fut,
67 // Fut: Future<Output = Output>,
68 // S: 'static,
69 // R1: 'static,
70 // A1: 'static + HandlerResolvable<(R1,), O, A1>,
71 // {
72 // async fn handle(
73 // &self,
74 // parameters: (R1,),
75 // additional_parameters: (A1,),
76 // state: Arc<S>,
77 // operation_state: &O,
78 // ) -> Output {
79 // todo!()
80 // }
81 // }
82
83 // #[async_trait::async_trait(?Send)]
84 // impl<R1, A1, A2, S, O, Output, F, Fut> GiteratedHandler<(R1,), (A1, A2), S, O, Output> for F
85 // where
86 // F: FnMut(R1, S, &O, A1, A2) -> Fut,
87 // Fut: Future<Output = Output>,
88 // S: 'static,
89 // R1: 'static,
90 // A1: 'static + HandlerResolvable<(R1,), O, A1>,
91 // A2: 'static + HandlerResolvable<(R1,), O, A2>,
92 // {
93 // async fn handle(
94 // &self,
95 // parameters: (R1,),
96 // additional_parameters: (A1, A2),
97 // state: Arc<S>,
98 // operation_state: &O,
99 // ) -> Output {
100 // todo!()
101 // }
102 // }
103
104 // #[async_trait::async_trait(?Send)]
105 // impl<R1, A1, A2, A3, S, O, Output, F, Fut> GiteratedHandler<(R1,), (A1, A2, A3), S, O, Output> for F
106 // where
107 // F: FnMut(R1, S, &O, A1, A2, A3) -> Fut,
108 // Fut: Future<Output = Output>,
109 // S: 'static,
110 // R1: 'static,
111 // A1: 'static + HandlerResolvable<(R1,), O, A1>,
112 // A2: 'static + HandlerResolvable<(R1,), O, A2>,
113 // A3: 'static + HandlerResolvable<(R1,), O, A3>,
114 // {
115 // async fn handle(
116 // &self,
117 // parameters: (R1,),
118 // additional_parameters: (A1, A2, A3),
119 // state: Arc<S>,
120 // operation_state: &O,
121 // ) -> Output {
122 // todo!()
123 // }
124 // }
125
126 // #[async_trait::async_trait(?Send)]
127 // impl<R1, R2, S, O, Output, F, Fut> GiteratedHandler<(R1, R2), (), S, O, Output> for F
128 // where
129 // F: FnMut(R1, R2, S, &O) -> Fut,
130 // Fut: Future<Output = Output>,
131 // S: 'static,
132 // R1: 'static,
133 // R2: 'static,
134 // {
135 // async fn handle(
136 // &self,
137 // parameters: (R1, R2),
138 // additional_parameters: (),
139 // state: Arc<S>,
140 // operation_state: &O,
141 // ) -> Output {
142 // todo!()
143 // }
144 // }
145
146 // #[async_trait::async_trait(?Send)]
147 // impl<R1, R2, A1, S, O, Output, F, Fut> GiteratedHandler<(R1, R2), (A1,), S, O, Output> for F
148 // where
149 // F: FnMut(R1, R2, S, &O, A1) -> Fut,
150 // Fut: Future<Output = Output>,
151 // S: 'static,
152 // R1: 'static,
153 // R2: 'static,
154 // A1: 'static + HandlerResolvable<(R1, R2), O, A1>,
155 // {
156 // async fn handle(
157 // &self,
158 // parameters: (R1, R2),
159 // additional_parameters: (A1,),
160 // state: Arc<S>,
161 // operation_state: &O,
162 // ) -> Output {
163 // todo!()
164 // }
165 // }
166
167 // #[async_trait::async_trait(?Send)]
168 // impl<R1, R2, A1, A2, S, O, Output, F, Fut> GiteratedHandler<(R1, R2), (A1, A2), S, O, Output> for F
169 // where
170 // F: FnMut(R1, R2, S, &O, A1, A2) -> Fut,
171 // Fut: Future<Output = Output>,
172 // S: 'static,
173 // R1: 'static,
174 // R2: 'static,
175 // A1: 'static + HandlerResolvable<(R1, R2), O, A1>,
176 // A2: 'static + HandlerResolvable<(R1, R2), O, A2>,
177 // {
178 // async fn handle(
179 // &self,
180 // parameters: (R1, R2),
181 // additional_parameters: (A1, A2),
182 // state: Arc<S>,
183 // operation_state: &O,
184 // ) -> Output {
185 // todo!()
186 // }
187 // }
188
189 // #[async_trait::async_trait(?Send)]
190 // impl<R1, R2, A1, A2, A3, S, O, Output, F, Fut>
191 // GiteratedHandler<(R1, R2), (A1, A2, A3), S, O, Output> for F
192 // where
193 // F: FnMut(R1, R2, S, &O, A1, A2, A3) -> Fut,
194 // Fut: Future<Output = Output>,
195 // S: 'static,
196 // R1: 'static,
197 // R2: 'static,
198 // A1: 'static + HandlerResolvable<(R1, R2), O, A1>,
199 // A2: 'static + HandlerResolvable<(R1, R2), O, A2>,
200 // A3: 'static + HandlerResolvable<(R1, R2), O, A3>,
201 // {
202 // async fn handle(
203 // &self,
204 // parameters: (R1, R2),
205 // additional_parameters: (A1, A2, A3),
206 // state: Arc<S>,
207 // operation_state: &O,
208 // ) -> Output {
209 // todo!()
210 // }
211 // }
212
213 // #[async_trait::async_trait(?Send)]
214 // impl<R1, R2, R3, S, O, Output, F, Fut> GiteratedHandler<(R1, R2, R3), (), S, O, Output> for F
215 // where
216 // F: FnMut(R1, R2, R3, S, &O) -> Fut,
217 // Fut: Future<Output = Output>,
218 // S: 'static,
219 // R1: 'static,
220 // R2: 'static,
221 // R3: 'static,
222 // {
223 // async fn handle(
224 // &self,
225 // parameters: (R1, R2, R3),
226 // additional_parameters: (),
227 // state: Arc<S>,
228 // operation_state: &O,
229 // ) -> Output {
230 // todo!()
231 // }
232 // }
233
234 // fn test_fn<O, A, S, V, F>(handler: F)
235 // where
236 // F: GiteratedHandler<(O, V), A, S, StackOperationState, Result<(), anyhow::Error>>,
237 // O: GiteratedObject,
238 // V: GiteratedObjectValue<Object = O>,
239 // {
240 // }
241
242 // fn other_fn() {
243 // let a = String::from("a");
244 // let test = move |object: User,
245 // value: GetValue,
246 // state: (),
247 // operation_state: &StackOperationState,
248 // authorized_user: AuthorizedUser| { async move { () } };
249
250 // let wrapper = HandlerWrapper::<(User, GetValue), _>::new((), test);
251 // }
252
253 // pub struct HandlerWrapper<P, O> {
254 // func: Box<dyn Fn(P, StackOperationState) -> LocalBoxFuture<'static, O>>,
255 // state: Arc<dyn Any + Send + Sync>,
256 // }
257
258 // impl<P, O> HandlerWrapper<P, O> {
259 // pub fn new<S, F, A>(state: S, handler: F) -> Self
260 // where
261 // F: GiteratedHandler<P, A, S, StackOperationState, O>,
262 // S: Send + Sync + 'static,
263 // A: HandlerResolvableGroup<P>,
264 // {
265 // let state = Arc::new(state);
266
267 // let func = |required: P, operation_state: StackOperationState| {
268 // // async move { handler.handle(required, (), state, &operation_state) }.boxed_local()
269 // todo!()
270 // };
271
272 // Self {
273 // func: Box::new(func),
274 // state,
275 // }
276 // }
277 // }
278
279 // #[async_trait::async_trait(?Send)]
280 // pub trait HandlerResolvable<RequiredParameters, OperationState, Output> {
281 // async fn from_handler_state(
282 // required_parameters: &RequiredParameters,
283 // operation_state: &OperationState,
284 // ) -> Output;
285 // }
286
287 // #[async_trait::async_trait(?Send)]
288 // impl HandlerResolvable<(User, GetValue), StackOperationState, Self> for Arc<GiteratedStack> {
289 // async fn from_handler_state(
290 // required_parameters: &(User, GetValue),
291 // operation_state: &StackOperationState,
292 // ) -> Self {
293 // todo!()
294 // }
295 // }
296
297 // // #[async_trait::async_trait(?Send)]
298 // // impl<O, D, T> HandlerResolvable<(O, D), StackOperationState, T> for T
299 // // where
300 // // O: GiteratedObject,
301 // // D: GiteratedOperation<O>,
302 // // T: FromOperationState<O, D>,
303 // // {
304 // // async fn from_handler_state(
305 // // required_parameters: &(O, D),
306 // // operation_state: &StackOperationState,
307 // // ) -> T {
308 // // todo!()
309 // // }
310 // // }
311
312 // #[async_trait::async_trait(?Send)]
313 // pub trait HandlerResolvableGroup<RequiredParameters> {
314 // async fn group_from_handler_state(
315 // required_parameters: &RequiredParameters,
316 // operation_state: &StackOperationState,
317 // ) -> Self;
318 // }
319
320 // #[async_trait::async_trait(?Send)]
321 // impl<RequiredParameters, A1> HandlerResolvableGroup<RequiredParameters> for (A1,)
322 // where
323 // A1: HandlerResolvable<RequiredParameters, StackOperationState, A1>,
324 // {
325 // async fn group_from_handler_state(
326 // required_parameters: &RequiredParameters,
327 // operation_state: &StackOperationState,
328 // ) -> (A1,) {
329 // (A1::from_handler_state(required_parameters, operation_state).await,)
330 // }
331 // }
332
333 // #[async_trait::async_trait(?Send)]
334 // impl<RequiredParameters, A1, A2> HandlerResolvableGroup<RequiredParameters> for (A1, A2)
335 // where
336 // A1: HandlerResolvable<RequiredParameters, StackOperationState, A1>,
337 // A2: HandlerResolvable<RequiredParameters, StackOperationState, A2>,
338 // {
339 // async fn group_from_handler_state(
340 // required_parameters: &RequiredParameters,
341 // operation_state: &StackOperationState,
342 // ) -> (A1, A2) {
343 // (
344 // A1::from_handler_state(required_parameters, operation_state).await,
345 // A2::from_handler_state(required_parameters, operation_state).await,
346 // )
347 // }
348 // }
349