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

ambee/giterated

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

More restructuring

Amber - ⁨1⁩ year ago

parent: tbd commit: ⁨10b7b7c

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