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/setting.rs⁩ - ⁨4721⁩ bytes
Raw
1 pub struct SettingGetterCallback(FfiValueUntyped);
2
3 impl Callback for SettingGetterCallback {
4 type CallbackFunc = unsafe extern "C" fn(
5 CallbackPtr<SettingGetterCallback>,
6 state: FfiValueMut<State>,
7 object: FfiValueRef<Object>,
8 ) -> RuntimeFuture<Result<Setting, ()>>;
9 }
10
11 pub trait IntoPluginSettingGetter<S, O, OS> {
12 unsafe extern "C" fn get_setting(
13 callback_ptr: CallbackPtr<SettingGetterCallback>,
14 state: FfiValueMut<State>,
15 object: FfiValueRef<Object>,
16 ) -> RuntimeFuture<Result<Setting, ()>>;
17
18 fn callback_ptr(&self) -> CallbackPtr<SettingGetterCallback> {
19 // unsafe { CallbackPtr::from_raw(self as *const _ as *const ()) }
20 todo!()
21 }
22 }
23
24 impl<F, S, O, OS, Fut> IntoPluginSettingGetter<S, O, OS> for F
25 where
26 Fut: Future<Output = Result<OS, OperationError<anyhow::Error>>> + Send + Sync + 'static,
27 S: Clone + Send + Sync + 'static,
28 O: GiteratedObject + Send + Sync + 'static,
29 OS: giterated_models::settings::Setting + Send + Sync + 'static,
30 F: Fn(S, O) -> Fut + Send + Sync + 'static,
31 {
32 unsafe extern "C" fn get_setting(
33 callback: CallbackPtr<SettingGetterCallback>,
34 state: FfiValueMut<State>,
35 mut object: FfiValueRef<Object>,
36 ) -> RuntimeFuture<Result<Setting, ()>> {
37 // let _guard = trace_span!(
38 // "get_setting handler",
39 // object = O::object_name(),
40 // setting = OS::name()
41 // )
42 // .entered();
43 // let state = unsafe { state.transmute_ref::<S>() };
44
45 // let object = unsafe { object.transmute_owned::<O>() };
46
47 // // Cast the callback ptr to ourselves
48 // let callback: *const F = std::mem::transmute(callback.0);
49 // let callback = callback.as_ref().unwrap();
50
51 // let state = state.clone();
52 // runtime_state.spawn_future(async move {
53 // let result = callback(state, *object).await;
54
55 // match result {
56 // Ok(success) => unsafe { Ok(NewAnySetting::new(success)) },
57 // Err(err) => match err {
58 // OperationError::Operation(_) => todo!(),
59 // OperationError::Internal(_) => todo!(),
60 // OperationError::Unhandled => todo!(),
61 // },
62 // }
63
64 todo!()
65 // })
66 }
67 }
68
69 pub trait IntoPluginSettingSetter<S, O, OS> {
70 unsafe extern "C" fn set_setting(
71 callback_ptr: CallbackPtr<SettingGetterCallback>,
72 state: &PluginState,
73 object: FfiValueRef<Object>,
74 setting: Setting,
75 ) -> RuntimeFuture<Result<(), ()>>;
76
77 fn callback_ptr(&self) -> CallbackPtr<SettingGetterCallback> {
78 // unsafe { CallbackPtr::from_raw(self as *const _ as *const ()) }
79 todo!()
80 }
81 }
82
83 impl<F, S, O, OS, Fut> IntoPluginSettingSetter<S, O, OS> for F
84 where
85 Fut: Future<Output = Result<(), OperationError<anyhow::Error>>>,
86 S: Clone,
87 O: GiteratedObject,
88 OS: giterated_models::settings::Setting,
89 F: Fn(S, O, OS) -> Fut,
90 {
91 unsafe extern "C" fn set_setting(
92 callback: CallbackPtr<SettingGetterCallback>,
93 state: &PluginState,
94 mut object: FfiValueRef<Object>,
95 _setting: Setting,
96 ) -> RuntimeFuture<Result<(), ()>> {
97 // let _guard = trace_span!(
98 // "get_setting handler",
99 // object = O::object_name(),
100 // setting = OS::name()
101 // )
102 // .entered();
103 // let _state = unsafe { state.transmute_ref::<S>() };
104
105 // let _object = unsafe { object.transmute_owned::<O>() };
106
107 // // Cast the callback ptr to ourselves
108 // let callback: *const F = std::mem::transmute(callback.0);
109 // let _callback = callback.as_ref().unwrap();
110
111 // let result = callback(state.clone(), *object);
112
113 // match result {
114 // Ok(setting) => Ok(NewAnySetting::new(setting)),
115 // Err(_) => todo!(),
116 // }
117 todo!()
118 }
119 }
120
121 pub struct SettingChangeCallback(FfiValueUntyped);
122
123 impl Callback for SettingChangeCallback {
124 type CallbackFunc = unsafe extern "C" fn(
125 &PluginState,
126 object: FfiValueRef<Object>,
127 setting_name: &str,
128 new_setting: Setting,
129 );
130 }
131
132 pub trait IntoSettingChangeCallback<S, O> {
133 unsafe extern "C" fn setting_changed(
134 state: &PluginState,
135 object: FfiValueRef<Object>,
136 setting_name: &str,
137 new_setting: Setting,
138 );
139 }
140
141 impl<F, S, O> IntoSettingChangeCallback<S, O> for F {
142 unsafe extern "C" fn setting_changed(
143 _state: &PluginState,
144 _object: FfiValueRef<Object>,
145 _setting_name: &str,
146 _new_setting: Setting,
147 ) {
148 todo!()
149 }
150 }
151