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

ambee/giterated

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

Structure refactoring

Amber - ⁨1⁩ year ago

parent: tbd commit: ⁨a8f41ac

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