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

ambee/giterated

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

Wow!

Amber - ⁨1⁩ year ago

parent: tbd commit: ⁨6530104

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