1 |
use crate::{
|
2 |
result::{FfiError, FfiResult},
|
3 |
value_ex::FfiValueUntyped,
|
4 |
FfiSlice, FfiSliceRef,
|
5 |
};
|
6 |
|
7 |
use super::{ObjectABI, VTable};
|
8 |
|
9 |
#[repr(C)]
|
10 |
pub struct Setting {
|
11 |
inner: FfiValueUntyped,
|
12 |
vtable: &'static VTable<Setting>,
|
13 |
}
|
14 |
|
15 |
impl<T: IntoSettingVTable> From<T> for Setting {
|
16 |
fn from(value: T) -> Self {
|
17 |
todo!()
|
18 |
}
|
19 |
}
|
20 |
|
21 |
impl ObjectABI for Setting {
|
22 |
type VTable = SettingVTable;
|
23 |
}
|
24 |
|
25 |
pub struct SettingVTable {
|
26 |
pub serialize: unsafe extern "C" fn(this: Setting) -> FfiResult<FfiSlice<[u8]>, FfiError>,
|
27 |
pub deserialize:
|
28 |
unsafe extern "C" fn(buffer: FfiSliceRef<[u8]>) -> FfiResult<Setting, FfiError>,
|
29 |
}
|
30 |
|
31 |
impl SettingVTable {
|
32 |
pub const fn new<S: IntoSettingVTable>() -> Self {
|
33 |
Self {
|
34 |
serialize: S::serialize,
|
35 |
deserialize: S::deserialize,
|
36 |
}
|
37 |
}
|
38 |
|
39 |
pub fn serialize(&self, setting: Setting) -> Result<Vec<u8>, FfiError> {
|
40 |
todo!()
|
41 |
}
|
42 |
|
43 |
pub fn deserialize(&self, buffer: &[u8]) -> Result<Setting, FfiError> {
|
44 |
todo!()
|
45 |
}
|
46 |
}
|
47 |
|
48 |
pub trait IntoSettingVTable: Sized {
|
49 |
const VTABLE: &'static VTable<Setting> = VTable::new(&SettingVTable::new::<Self>());
|
50 |
|
51 |
unsafe extern "C" fn serialize(this: Setting) -> FfiResult<FfiSlice<[u8]>, FfiError>;
|
52 |
unsafe extern "C" fn deserialize(buffer: FfiSliceRef<[u8]>) -> FfiResult<Setting, FfiError>;
|
53 |
}
|
54 |
|