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

ambee/giterated

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

Pre vtable changes

Amber - ⁨1⁩ year ago

parent: tbd commit: ⁨d17a4b2

⁨giterated-abi/src/vtable/operation.rs⁩ - ⁨2070⁩ bytes
Raw
1 use std::ffi::CStr;
2
3 use crate::{
4 result::{Error, Result},
5 value_ex::{FfiValueRefUntyped, FfiValueUntyped},
6 FfiSlice, FfiSliceRef, FfiValue, FfiValueRef,
7 };
8
9 use super::{ObjectABI, VTable};
10
11 #[repr(C)]
12 pub struct Operation {
13 inner: FfiValue<()>,
14 vtable: &'static VTable<Operation>,
15 }
16
17 impl ObjectABI for Operation {
18 type VTable = OperationVTable;
19 }
20
21 pub struct OperationVTable {
22 pub operation_kind: &'static CStr,
23 pub operation_serialize:
24 unsafe extern "C" fn(this: FfiValueRef<Operation>) -> Result<FfiSlice<[u8]>, Error>,
25 pub operation_deserialize:
26 unsafe extern "C" fn(buffer: FfiSliceRef<[u8]>) -> Result<Operation, Error>,
27 pub success_serialize:
28 unsafe extern "C" fn(success: FfiValueRefUntyped) -> Result<FfiSlice<[u8]>, Error>,
29 pub success_deserialize:
30 unsafe extern "C" fn(buffer: FfiSliceRef<[u8]>) -> Result<FfiValueUntyped, Error>,
31 pub failure_serialize:
32 unsafe extern "C" fn(failure: FfiValueRefUntyped) -> Result<FfiSlice<[u8]>, Error>,
33 pub failure_deserialize:
34 unsafe extern "C" fn(buffer: FfiSliceRef<[u8]>) -> Result<FfiValueUntyped, Error>,
35 }
36
37 impl OperationVTable {
38 pub const fn new<O: IntoOperationVTable>() -> Self {
39 todo!()
40 }
41 }
42
43 pub trait IntoOperationVTable {
44 fn operation_kind() -> &'static CStr;
45 unsafe extern "C" fn operation_serialize(
46 this: FfiValueRef<Operation>,
47 ) -> Result<FfiSlice<[u8]>, Error>;
48 unsafe extern "C" fn operation_deserialize(
49 buffer: FfiSliceRef<[u8]>,
50 ) -> Result<Operation, Error>;
51 unsafe extern "C" fn success_serialize(
52 success: FfiValueRefUntyped,
53 ) -> Result<FfiSlice<[u8]>, Error>;
54 unsafe extern "C" fn success_deserialize(
55 buffer: FfiSliceRef<[u8]>,
56 ) -> Result<FfiValueUntyped, Error>;
57 unsafe extern "C" fn failure_serialize(
58 failure: FfiValueRefUntyped,
59 ) -> Result<FfiSlice<[u8]>, Error>;
60 unsafe extern "C" fn failure_deserialize(
61 buffer: FfiSliceRef<[u8]>,
62 ) -> Result<FfiValueUntyped, Error>;
63 }
64