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

ambee/giterated

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

Before

Amber - ⁨1⁩ year ago

parent: tbd commit: ⁨e432306

⁨giterated-core/src/callback/operation.rs⁩ - ⁨4561⁩ bytes
Raw
1 pub struct OperationHandlerCallback(FfiValueUntyped);
2
3 impl Callback for OperationHandlerCallback {
4 type CallbackFunc = unsafe extern "C" fn(
5 CallbackPtr<OperationHandlerCallback>,
6 state: FfiValueMut<State>,
7 object: FfiValueRef<Object>,
8 operation: FfiValueRef<Operation>,
9 ) -> RuntimeFuture<
10 FfiResult<FfiValueUntyped, OperationError<FfiValueUntyped>>,
11 >;
12 }
13
14 pub trait IntoPluginOperationHandler<S, O: GiteratedObject, D: GiteratedOperation<O>, A> {
15 unsafe extern "C" fn handle(
16 callback_ptr: CallbackPtr<OperationHandlerCallback>,
17 state: FfiValueMut<State>,
18 object: FfiValueRef<Object>,
19 operation: FfiValueRef<Operation>,
20 ) -> RuntimeFuture<FfiResult<FfiValueUntyped, OperationError<FfiValueUntyped>>>;
21 fn callback_ptr(&self) -> CallbackPtr<OperationHandlerCallback>;
22 }
23
24 impl<F, S, O, D, Fut> IntoPluginOperationHandler<S, O, D, ()> for F
25 where
26 Fut: Future<Output = Result<D::Success, OperationError<D::Failure>>> + Send + Sync,
27 F: Fn(S, O, D) -> Fut + Send + Sync + 'static,
28 S: Clone + Debug + Send + Sync + 'static,
29 O: Debug + GiteratedObject + 'static,
30 D: Debug + GiteratedOperation<O> + 'static,
31 {
32 unsafe extern "C" fn handle(
33 callback: CallbackPtr<OperationHandlerCallback>,
34 state: FfiValueMut<State>,
35 object: FfiValueRef<Object>,
36 operation: FfiValueRef<Operation>,
37 ) -> RuntimeFuture<FfiResult<FfiValueUntyped, OperationError<FfiValueUntyped>>> {
38 todo!()
39 // let _guard = trace_span!(
40 // "operation handler",
41 // object = type_name::<O>(),
42 // operation = type_name::<D>()
43 // )
44 // .entered();
45 // let state = unsafe { state.transmute_ref::<S>() };
46
47 // // Since this is Rust code, we know that the AnyObject and AnyOperation are just boxes
48 // let object = unsafe { object.transmute_owned::<O>() };
49 // let operation = unsafe { operation.transmute_owned::<D>() };
50
51 // // Cast the callback ptr to ourselves
52 // let callback: *const F = std::mem::transmute(callback.0);
53 // let callback = callback.as_ref().unwrap();
54
55 // let state = state.clone();
56 // runtime_state.spawn_future(async move {
57 // let result = callback(state, *object, *operation).await;
58
59 // match result {
60 // Ok(success) => unsafe {
61 // todo!()
62 // // Ok(AnySuccess::from_raw(
63 // // FFIBox::from_box(Box::new(success)).untyped(),
64 // // OperationVTable::new::<O, D>(),
65 // // ))
66 // },
67 // Err(err) => match err {
68 // OperationError::Operation(_) => todo!(),
69 // OperationError::Internal(_) => todo!(),
70 // OperationError::Unhandled => todo!(),
71 // },
72 // }
73 // })
74 }
75
76 fn callback_ptr(&self) -> CallbackPtr<OperationHandlerCallback> {
77 // unsafe { CallbackPtr::from_raw(self as *const _ as *const ()) }
78
79 todo!()
80 }
81 }
82
83 impl<F, S, O, D, Fut, A1> IntoPluginOperationHandler<S, O, D, (A1,)> for F
84 where
85 Fut: Future<Output = Result<D::Success, OperationError<D::Failure>>>,
86 F: Fn(S, O, D, A1) -> Fut,
87 S: Clone + Debug,
88 O: Debug + GiteratedObject,
89 D: Debug + GiteratedOperation<O>,
90 {
91 unsafe extern "C" fn handle(
92 _callback_ptr: CallbackPtr<OperationHandlerCallback>,
93 state: FfiValueMut<State>,
94 object: FfiValueRef<Object>,
95 operation: FfiValueRef<Operation>,
96 ) -> RuntimeFuture<FfiResult<FfiValueUntyped, OperationError<FfiValueUntyped>>> {
97 todo!()
98 }
99
100 fn callback_ptr(&self) -> CallbackPtr<OperationHandlerCallback> {
101 todo!()
102 }
103 }
104
105 impl<F, S, O, D, Fut, A1, A2> IntoPluginOperationHandler<S, O, D, (A1, A2)> for F
106 where
107 Fut: Future<Output = Result<D::Success, OperationError<D::Failure>>>,
108 F: Fn(S, O, D, A1, A2) -> Fut,
109 S: Clone + Debug,
110 O: Debug + GiteratedObject,
111 D: Debug + GiteratedOperation<O>,
112 {
113 unsafe extern "C" fn handle(
114 _callback_ptr: CallbackPtr<OperationHandlerCallback>,
115 state: FfiValueMut<State>,
116 object: FfiValueRef<Object>,
117 operation: FfiValueRef<Operation>,
118 ) -> RuntimeFuture<FfiResult<FfiValueUntyped, OperationError<FfiValueUntyped>>> {
119 todo!()
120 }
121
122 fn callback_ptr(&self) -> CallbackPtr<OperationHandlerCallback> {
123 todo!()
124 }
125 }
126