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

ambee/giterated

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

Structure refactoring

Amber - ⁨1⁩ year ago

parent: tbd commit: ⁨a8f41ac

⁨giterated-core/src/callback/value.rs⁩ - ⁨3393⁩ bytes
Raw
1 #[derive(Copy, Clone)]
2 pub struct ValueGetterCallback(CallbackPtr<ValueGetterCallback>);
3
4 impl Callback for ValueGetterCallback {
5 type CallbackFunc = unsafe extern "C" fn(
6 CallbackPtr<ValueGetterCallback>,
7 state: FfiValueMut<State>,
8 object: FfiValueRef<Object>,
9 ) -> RuntimeFuture<FfiResult<Value, FfiError>>;
10 }
11
12 pub trait IntoPluginValueGetter<S, O, V> {
13 unsafe extern "C" fn get_value(
14 callback: CallbackPtr<SettingGetterCallback>,
15 state: FfiValueMut<State>,
16 object: FfiValueRef<Object>,
17 ) -> RuntimeFuture<FfiResult<Value, FfiError>>;
18
19 fn callback_ptr(&self) -> CallbackPtr<SettingGetterCallback>;
20 }
21
22 impl<F, S, O, V, Fut> IntoPluginValueGetter<S, O, V> for F
23 where
24 Fut: Future<Output = Result<V, OperationError<anyhow::Error>>> + Send + Sync,
25 S: Clone + Send + Sync + 'static,
26 O: GiteratedObject + 'static,
27 V: GiteratedObjectValue<Object = O> + Send + Sync + 'static,
28 F: Fn(S, O) -> Fut + Send + Sync + 'static,
29 {
30 unsafe extern "C" fn get_value(
31 callback: CallbackPtr<SettingGetterCallback>,
32 state: FfiValueMut<State>,
33 mut object: FfiValueRef<Object>,
34 ) -> RuntimeFuture<FfiResult<Value, FfiError>> {
35 // let _guard = trace_span!(
36 // "get_value handler",
37 // object = O::object_name(),
38 // value = V::value_name()
39 // )
40 // .entered();
41 // let state = unsafe { state.transmute_ref::<S>() };
42
43 // let object = unsafe { object.transmute_owned::<O>() };
44
45 // // Cast the callback ptr to ourselves
46 // let callback: *const F = std::mem::transmute(callback.0);
47 // let callback = callback.as_ref().unwrap();
48
49 // let state = state.clone();
50 // runtime_state.spawn_future(async move {
51 // let result = callback(state, *object).await;
52
53 // match result {
54 // Ok(success) => unsafe { Ok(NewAnyValue::new(success)) },
55 // Err(err) => match err {
56 // OperationError::Operation(_) => todo!(),
57 // OperationError::Internal(_) => todo!(),
58 // OperationError::Unhandled => todo!(),
59 // },
60 // }
61 // })
62
63 todo!()
64 }
65
66 fn callback_ptr(&self) -> CallbackPtr<SettingGetterCallback> {
67 todo!()
68 // unsafe { CallbackPtr::from_raw(self as *const _ as *const ()) }
69 }
70 }
71
72 pub struct ValueChangeCallback(CallbackPtr<ValueChangeCallback>);
73
74 impl Callback for ValueChangeCallback {
75 type CallbackFunc = unsafe extern "C" fn(
76 &PluginState,
77 object: FfiValueRef<Object>,
78 value_name: FfiSliceRef<str>,
79 new_value: Value,
80 ) -> RuntimeFuture<()>;
81 }
82
83 pub trait IntoValueChangeCallback<S, O> {
84 unsafe extern "C" fn value_changed(
85 callback: CallbackPtr<ValueChangeCallback>,
86 state: FfiValueMut<State>,
87 object: FfiValueRef<Object>,
88 value_name: FfiSliceRef<str>,
89 new_value: Value,
90 ) -> RuntimeFuture<()>;
91 }
92
93 impl<F, S, O> IntoValueChangeCallback<S, O> for F {
94 unsafe extern "C" fn value_changed(
95 callback: CallbackPtr<ValueChangeCallback>,
96 state: FfiValueMut<State>,
97 _object: FfiValueRef<Object>,
98 _value_name: FfiSliceRef<str>,
99 _new_value: Value,
100 ) -> RuntimeFuture<()> {
101 todo!()
102 }
103 }
104