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

ambee/giterated

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

Fucking whatever there you go

Amber - ⁨2⁩ years ago

parent: tbd commit: ⁨57c2ca5

⁨giterated-plugin/src/new_stack/runtime_handler.rs⁩ - ⁨1819⁩ bytes
Raw
1 use std::fmt::Debug;
2 use std::sync::Arc;
3
4 use giterated_models::{
5 error::OperationError,
6 object::{GiteratedObject, Object, ObjectRequestError},
7 object_backend::ObjectBackend,
8 operation::GiteratedOperation,
9 };
10
11 use crate::vtable::{AnyFailure, AnySuccess, OperationVTable};
12
13 use super::PluginState;
14
15 #[derive(Clone)]
16 pub struct RuntimeHandle {
17 inner: Arc<RuntimeHandleInner>,
18 }
19
20 impl RuntimeHandle {
21 pub async fn handle_serialized(
22 &self,
23 operation_name: &str,
24 object: &str,
25 operation: &[u8],
26 ) -> Result<Vec<u8>, OperationError<Vec<u8>>> {
27 todo!()
28 }
29 }
30
31 #[repr(C)]
32 struct RuntimeHandleInner {
33 state: PluginState,
34 handle_serialized: unsafe extern "C" fn(
35 object_kind: &str,
36 operation_name: &str,
37 object: &str,
38 operation_payload: &[u8],
39 ) -> HandlerResult,
40 }
41
42 unsafe impl Send for RuntimeHandleInner {}
43 unsafe impl Sync for RuntimeHandleInner {}
44
45 #[repr(C)]
46 struct HandlerResult {
47 operation_vtable: OperationVTable,
48 result: Result<AnySuccess, OperationError<AnyFailure>>,
49 }
50
51 #[async_trait::async_trait(?Send)]
52 impl<S: Send + Sync + Clone> ObjectBackend<S> for RuntimeHandle {
53 async fn object_operation<O, D>(
54 &self,
55 object: O,
56 operation: &str,
57 payload: D,
58 operation_state: &S,
59 ) -> Result<D::Success, OperationError<D::Failure>>
60 where
61 O: GiteratedObject + Debug + 'static,
62 D: GiteratedOperation<O> + Debug + 'static,
63 D::Success: Clone,
64 D::Failure: Clone,
65 {
66 todo!()
67 }
68
69 async fn get_object<O: GiteratedObject + Debug + 'static>(
70 &self,
71 object_str: &str,
72 operation_state: &S,
73 ) -> Result<Object<S, O, Self>, OperationError<ObjectRequestError>> {
74 todo!()
75 }
76 }
77