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

ambee/giterated

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

Before

Amber - ⁨1⁩ year ago

parent: tbd commit: ⁨e432306

⁨giterated-plugin/src/state.rs⁩ - ⁨2470⁩ bytes
Raw
1 use giterated_abi::prelude::*;
2 use giterated_abi::value_ex::FfiValueUntyped;
3 use giterated_abi::vtable::ObjectABI;
4 use giterated_abi::vtable::VTable;
5
6 #[repr(transparent)]
7 pub struct State {
8 inner: StateHandle,
9 }
10
11 #[repr(transparent)]
12 struct StateHandle {
13 state: FfiValue<()>,
14 }
15
16 #[repr(C)]
17 struct StateItem<T: ?Sized> {
18 /// The pointer to the next item.
19 ///
20 /// `next_item` is most likely always an `FfiValue<StateItem<()>>` and that's how we free them.
21 next_item: *const StateItem<()>,
22 pub state_uuid: u128,
23 pub state: T,
24 }
25
26 impl Drop for State {
27 fn drop(&mut self) {
28 let state_manager = unsafe { StateManager::new(self) };
29
30 for state in state_manager {}
31 }
32 }
33
34 struct StateManager<'s> {
35 state: &'s mut State,
36 last: Option<StateHandle>,
37 }
38
39 impl<'s> StateManager<'s> {
40 pub unsafe fn new(handle: &'s mut State) -> Self {
41 todo!()
42 }
43
44 pub unsafe fn write_state<S: StateUUID>(&mut self, state: S) -> Self {
45 todo!()
46 }
47
48 pub unsafe fn get_state<S: StateUUID>(&mut self) -> Option<&S> {
49 todo!()
50 }
51 }
52
53 impl<'s> Iterator for StateManager<'s> {
54 type Item = StateItem<()>;
55
56 fn next(&mut self) -> Option<StateItem<()>> {
57 todo!()
58 }
59 }
60
61 pub trait StateUUID {
62 fn uuid() -> u128;
63
64 fn unsafe_hint_copy() -> Option<bool> {
65 None
66 }
67 }
68
69 /// State values for the current execution domain. 99.99% of the time this means "plugin-specific"
70 ///
71 /// The remainder 0.01% of the time it refers to the daemon's runtime domain.
72 pub struct DomainState(StateItem<()>);
73
74 impl StateUUID for DomainState {
75 fn uuid() -> u128 {
76 todo!()
77 }
78 }
79
80 pub struct RuntimeState(StateItem<&'static VTable<Runtime>>);
81
82 impl StateUUID for RuntimeState {
83 fn uuid() -> u128 {
84 todo!()
85 }
86 }
87
88 impl RuntimeState {
89 pub fn queue_insert_state<S: StateUUID>(&mut self, state: S) {
90 todo!()
91 }
92 }
93
94 pub struct Runtime {
95 pub queue_insert_state: unsafe extern "C" fn(state_uuid: u128, state: FfiValueUntyped),
96 }
97
98 impl ObjectABI for Runtime {
99 type VTable = Runtime;
100 }
101
102 pub trait FromState: Sized {
103 fn from_state(state: &mut State) -> Result<Self, anyhow::Error>;
104 }
105
106 impl<T: StateUUID> FromState for T {
107 fn from_state(state: &mut State) -> Result<Self, anyhow::Error> {
108 todo!()
109 }
110 }
111
112 impl<T: FromState> FromState for Option<T> {
113 fn from_state(state: &mut State) -> Result<Self, anyhow::Error> {
114 todo!()
115 }
116 }
117