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

ambee/giterated

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

no clue what this is

Amber - ⁨1⁩ year ago

parent: tbd commit: ⁨7889bf6

⁨giterated-runtime/giterated-abi/src/vtable/object.rs⁩ - ⁨1934⁩ bytes
Raw
1 use std::{
2 ffi::{CStr, CString},
3 str::FromStr,
4 };
5
6 use giterated_models::object::GiteratedObject;
7
8 use crate::{
9 result::{FfiError, FfiResult},
10 value_ex::FfiValueUntyped,
11 FfiSlice, FfiSliceRef, FfiValueRef,
12 };
13
14 use super::{ObjectABI, VTable};
15
16 #[repr(C)]
17 pub struct Object {
18 inner: FfiValueUntyped,
19 vtable: &'static VTable<Object>,
20 }
21
22 impl Object {
23 pub fn home_uri(&self) -> String {
24 todo!()
25 }
26
27 pub unsafe fn cast<T: GiteratedObject>(self) -> T {
28 todo!()
29 }
30 }
31
32 impl<O: IntoObjectVTable> From<O> for Object {
33 fn from(value: O) -> Self {
34 todo!()
35 }
36 }
37
38 impl ToString for Object {
39 fn to_string(&self) -> String {
40 todo!()
41 }
42 }
43
44 impl FromStr for Object {
45 type Err = FfiError;
46
47 fn from_str(s: &str) -> Result<Self, Self::Err> {
48 todo!()
49 }
50 }
51
52 impl ObjectABI for Object {
53 type VTable = ObjectVTable;
54 }
55
56 pub struct ObjectVTable {
57 pub object_kind: unsafe extern "C" fn() -> &'static str,
58 pub to_str: unsafe extern "C" fn(this: FfiValueRef<Object>) -> FfiSlice<str>,
59 pub from_str: unsafe extern "C" fn(from: FfiSliceRef<str>) -> FfiResult<Object, FfiError>,
60 pub home_uri: unsafe extern "C" fn(this: FfiValueRef<Object>) -> FfiSlice<str>,
61 }
62
63 impl ObjectVTable {
64 pub const fn new<O: IntoObjectVTable>() -> Self {
65 Self {
66 object_kind: O::object_kind,
67 to_str: O::to_str,
68 from_str: O::from_str,
69 home_uri: O::home_uri,
70 }
71 }
72 }
73
74 pub trait IntoObjectVTable: Sized {
75 const VTABLE: &'static VTable<Object> = VTable::new(&ObjectVTable::new::<Self>());
76
77 unsafe extern "C" fn object_kind() -> &'static str;
78 unsafe extern "C" fn to_str(this: FfiValueRef<Object>) -> FfiSlice<str>;
79 unsafe extern "C" fn from_str(from: FfiSliceRef<str>) -> FfiResult<Object, FfiError>;
80 unsafe extern "C" fn home_uri(this: FfiValueRef<Object>) -> FfiSlice<str>;
81 }
82