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

ambee/giterated

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

insanity

Amber - ⁨1⁩ year ago

parent: tbd commit: ⁨6ea28ab

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