use std::{ ffi::{CStr, CString}, str::FromStr, }; use giterated_models::object::GiteratedObject; use crate::{ result::{FfiError, FfiResult}, value_ex::FfiValueUntyped, FfiSlice, FfiSliceRef, FfiValueRef, }; use super::{ObjectABI, VTable}; #[repr(C)] pub struct Object { inner: FfiValueUntyped, vtable: &'static VTable, } impl Object { pub fn home_uri(&self) -> String { todo!() } pub unsafe fn cast(self) -> T { todo!() } } impl From for Object { fn from(value: O) -> Self { todo!() } } impl ToString for Object { fn to_string(&self) -> String { todo!() } } impl FromStr for Object { type Err = FfiError; fn from_str(s: &str) -> Result { todo!() } } impl ObjectABI for Object { type VTable = ObjectVTable; } pub struct ObjectVTable { pub object_kind: unsafe extern "C" fn() -> &'static str, pub to_str: unsafe extern "C" fn(this: FfiValueRef) -> FfiSlice, pub from_str: unsafe extern "C" fn(from: FfiSliceRef) -> FfiResult, pub home_uri: unsafe extern "C" fn(this: FfiValueRef) -> FfiSlice, } impl ObjectVTable { pub const fn new() -> Self { Self { object_kind: O::object_kind, to_str: O::to_str, from_str: O::from_str, home_uri: O::home_uri, } } } pub trait IntoObjectVTable: Sized { const VTABLE: &'static VTable = VTable::new(&ObjectVTable::new::()); unsafe extern "C" fn object_kind() -> &'static str; unsafe extern "C" fn to_str(this: FfiValueRef) -> FfiSlice; unsafe extern "C" fn from_str(from: FfiSliceRef) -> FfiResult; unsafe extern "C" fn home_uri(this: FfiValueRef) -> FfiSlice; }