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/value.rs⁩ - ⁨845⁩ bytes
Raw
1 use crate::{
2 result::{Error, Result},
3 FfiSlice, FfiSliceRef,
4 };
5
6 use super::{ObjectABI, VTable};
7
8 #[repr(C)]
9 pub struct Value {
10 inner: (),
11 vtable: &'static VTable<Value>,
12 }
13
14 impl ObjectABI for Value {
15 type VTable = ValueVTable;
16 }
17
18 pub struct ValueVTable {
19 pub serialize: unsafe extern "C" fn(buffer: FfiSliceRef<[u8]>) -> Result<Value, Error>,
20 pub deserialize: unsafe extern "C" fn(this: Value) -> Result<FfiSlice<[u8]>, Error>,
21 }
22
23 impl ValueVTable {
24 pub const fn new<V: IntoValueVTable>() -> Self {
25 Self {
26 serialize: V::serialize,
27 deserialize: V::deserialize,
28 }
29 }
30 }
31
32 pub trait IntoValueVTable {
33 unsafe extern "C" fn serialize(buffer: FfiSliceRef<[u8]>) -> Result<Value, Error>;
34 unsafe extern "C" fn deserialize(this: Value) -> Result<FfiSlice<[u8]>, Error>;
35 }
36