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