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

ambee/giterated

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

Spinning

Amber - ⁨1⁩ year ago

parent: tbd commit: ⁨1788060

⁨giterated-runtime/giterated-abi/src/vtable/runtime.rs⁩ - ⁨2998⁩ bytes
Raw
1 use giterated_models::{
2 error::OperationError,
3 object::{GiteratedObject, ObjectRequestError},
4 object_backend::ObjectBackend,
5 operation::{GiteratedOperation, OperationState},
6 };
7
8 use crate::{
9 result::{FfiError, FfiResult},
10 state::State,
11 value_ex::FfiValueUntyped,
12 FfiFuture, FfiSliceRef, FfiValueMut,
13 };
14
15 use core::fmt::Debug;
16
17 use super::{Object, ObjectABI};
18
19 #[derive(Clone)]
20 pub struct RuntimeHandle;
21
22 impl ObjectABI for RuntimeHandle {
23 type VTable = RuntimeVTable;
24 }
25
26 impl RuntimeHandle {
27 pub async fn handle_serialized(
28 &self,
29 object: &str,
30 operation_type: &str,
31 operation_payload: &[u8],
32 ) -> Result<Vec<u8>, OperationError<Vec<u8>>> {
33 todo!()
34 }
35
36 pub async fn handle_typed<O, D>(
37 &self,
38 object: O,
39 operation: D,
40 ) -> Result<D::Success, OperationError<D::Failure>>
41 where
42 O: GiteratedObject,
43 D: GiteratedOperation<O>,
44 {
45 todo!()
46 }
47
48 pub async fn inner_get_object(
49 &self,
50 object_str: &str,
51 ) -> Result<Object, OperationError<ObjectRequestError>> {
52 todo!()
53 }
54 }
55
56 #[derive(Clone, Copy)]
57 pub struct RuntimeVTable {
58 pub(crate) handle_fn: unsafe extern "C" fn(
59 FfiSliceRef<str>,
60 FfiSliceRef<str>,
61 FfiSliceRef<str>,
62 FfiSliceRef<[u8]>,
63 FfiSliceRef<[u8]>,
64 ) -> FfiFuture<
65 FfiResult<FfiValueUntyped, OperationError<FfiError>>,
66 >,
67 pub(crate) get_object:
68 unsafe extern "C" fn(
69 &str,
70 state: FfiValueMut<State>,
71 ) -> FfiResult<Object, OperationError<ObjectRequestError>>,
72 }
73
74 unsafe impl Send for RuntimeVTable {}
75 unsafe impl Sync for RuntimeVTable {}
76
77 pub trait IntoRuntimeVtable {
78 unsafe extern "C" fn handle(
79 object_kind: FfiSliceRef<str>,
80 operation_name: FfiSliceRef<str>,
81 object: FfiSliceRef<str>,
82 operation_payload: FfiSliceRef<[u8]>,
83 operation_state: FfiSliceRef<[u8]>,
84 ) -> FfiFuture<FfiResult<FfiValueUntyped, OperationError<FfiError>>>;
85
86 unsafe extern "C" fn get_object(
87 object_str: &str,
88 operation_state: FfiValueMut<State>,
89 ) -> FfiResult<Object, OperationError<ObjectRequestError>>;
90 }
91
92 #[async_trait::async_trait(?Send)]
93 impl ObjectBackend for RuntimeHandle {
94 async fn object_operation<O, D>(
95 &self,
96 object: O,
97 operation: &str,
98 payload: D,
99 operation_state: &OperationState,
100 ) -> Result<D::Success, OperationError<D::Failure>>
101 where
102 O: GiteratedObject + Debug + 'static,
103 D: GiteratedOperation<O> + Debug + 'static,
104 D::Success: Clone,
105 D::Failure: Clone,
106 {
107 todo!()
108 }
109
110 async fn get_object<O: GiteratedObject + Debug + 'static>(
111 &self,
112 object_str: &str,
113 operation_state: &OperationState,
114 ) -> Result<giterated_models::object::Object<O, Self>, OperationError<ObjectRequestError>> {
115 todo!()
116 }
117 }
118