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

ambee/giterated

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

More progress :)

Amber - ⁨1⁩ year ago

parent: tbd commit: ⁨92c3f32

⁨giterated-plugin/src/callback/mod.rs⁩ - ⁨1895⁩ bytes
Raw
1 mod operation;
2
3 use giterated_models::{
4 error::OperationError,
5 object::{GiteratedObject, Object, ObjectRequestError},
6 object_backend::ObjectBackend,
7 operation::{GiteratedOperation, OperationState},
8 };
9 use std::fmt::Debug;
10
11 pub use operation::*;
12 mod value;
13 pub use value::*;
14 mod setting;
15 pub use setting::*;
16
17 use crate::{vtable::RuntimeVTable, AnyObject, AnyOperation};
18
19 /// A container for a callback pointer, used to provide an internal callback function or
20 /// state to a plugin when performing a callback.
21 #[derive(Clone, Copy)]
22 #[repr(C)]
23 pub struct CallbackPtr(*const ());
24
25 impl CallbackPtr {
26 pub unsafe fn from_raw(callback: *const ()) -> Self {
27 Self(callback)
28 }
29 }
30
31 #[derive(Clone)]
32 #[repr(C)]
33 pub struct RuntimeState {
34 pub vtable: RuntimeVTable,
35 pub operation_state: OperationState,
36 }
37
38 impl RuntimeState {
39 pub unsafe fn from_static() -> Self {
40 let runtime = giterated_static_runtime::get_runtime_reference();
41
42 let runtime = runtime.cast::<Box<RuntimeState>>().as_ref();
43
44 *runtime.clone()
45 }
46 }
47
48 #[async_trait::async_trait(?Send)]
49 impl ObjectBackend for RuntimeState {
50 async fn object_operation<O, D>(
51 &self,
52 object: O,
53 _operation: &str,
54 payload: D,
55 _operation_state: &OperationState,
56 ) -> Result<D::Success, OperationError<D::Failure>>
57 where
58 O: GiteratedObject + Debug + 'static,
59 D: GiteratedOperation<O> + Debug + 'static,
60 D::Success: Clone,
61 D::Failure: Clone,
62 {
63 let _object = AnyObject::new(object);
64 let _operation = AnyOperation::new(payload);
65
66 todo!()
67 }
68
69 async fn get_object<O: GiteratedObject + Debug + 'static>(
70 &self,
71 _object_str: &str,
72 _operation_state: &OperationState,
73 ) -> Result<Object<O, Self>, OperationError<ObjectRequestError>> {
74 todo!()
75 }
76 }
77