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/object.rs⁩ - ⁨1012⁩ bytes
Raw
1 use std::ffi::CStr;
2
3 use crate::{
4 result::{Error, Result},
5 FfiSlice, FfiSliceRef, FfiValueRef,
6 };
7
8 use super::{ObjectABI, VTable};
9
10 #[repr(C)]
11 pub struct Object {
12 inner: (),
13 vtable: &'static VTable<Object>,
14 }
15
16 impl ObjectABI for Object {
17 type VTable = ObjectVTable;
18 }
19
20 pub struct ObjectVTable {
21 pub object_kind: &'static CStr,
22 pub to_str: unsafe extern "C" fn(this: FfiValueRef<Object>) -> FfiSlice<str>,
23 pub from_str: unsafe extern "C" fn(from: FfiSliceRef<str>) -> Result<Object, Error>,
24 pub home_uri: unsafe extern "C" fn(this: FfiValueRef<Object>) -> FfiSlice<str>,
25 }
26
27 impl ObjectVTable {
28 pub fn new<O: IntoObjectVTable>() -> Self {
29 todo!()
30 }
31 }
32
33 pub trait IntoObjectVTable {
34 fn object_kind() -> &'static CStr;
35 unsafe extern "C" fn to_str(this: FfiValueRef<Object>) -> FfiSlice<str>;
36 unsafe extern "C" fn from_str(from: FfiSliceRef<str>) -> Result<Object, Error>;
37 unsafe extern "C" fn home_uri(this: FfiValueRef<Object>) -> FfiSlice<str>;
38 }
39