pub trait FromOperationState: Sized { fn from_operation_state( state: &mut State, object: &O, operation: &D, ) -> Result>; } pub struct StateExtractor(T); impl FromState for StateExtractor { fn from_state(state: &mut State) -> Result { todo!() } } use giterated_abi::prelude::*; use giterated_abi::value_ex::FfiValueUntyped; use giterated_abi::vtable::ObjectABI; use giterated_abi::vtable::VTable; use giterated_models::error::OperationError; #[repr(transparent)] pub struct State { inner: StateHandle, } #[repr(transparent)] struct StateHandle { state: FfiValue<()>, } #[repr(C)] struct StateItem { /// The pointer to the next item. /// /// `next_item` is most likely always an `FfiValue>` and that's how we free them. next_item: *const StateItem<()>, pub state_uuid: u128, pub state: T, } impl Drop for State { fn drop(&mut self) { let state_manager = unsafe { StateManager::new(self) }; for state in state_manager {} } } struct StateManager<'s> { state: &'s mut State, last: Option, } impl<'s> StateManager<'s> { pub unsafe fn new(handle: &'s mut State) -> Self { todo!() } pub unsafe fn write_state(&mut self, state: S) -> Self { todo!() } pub unsafe fn get_state(&mut self) -> Option<&S> { todo!() } } impl<'s> Iterator for StateManager<'s> { type Item = StateItem<()>; fn next(&mut self) -> Option> { todo!() } } pub trait StateUUID { fn uuid() -> u128; fn unsafe_hint_copy() -> Option { None } } /// State values for the current execution domain. 99.99% of the time this means "plugin-specific" /// /// The remainder 0.01% of the time it refers to the daemon's runtime domain. pub struct DomainState(StateItem<()>); impl StateUUID for DomainState { fn uuid() -> u128 { todo!() } } pub struct RuntimeState(StateItem<&'static VTable>); impl StateUUID for RuntimeState { fn uuid() -> u128 { todo!() } } impl RuntimeState { pub fn queue_insert_state(&mut self, state: S) { todo!() } } pub struct Runtime { pub queue_insert_state: unsafe extern "C" fn(state_uuid: u128, state: FfiValueUntyped), } impl ObjectABI for Runtime { type VTable = Runtime; } pub trait FromState: Sized { fn from_state(state: &mut State) -> Result; } impl FromState for T { fn from_state(state: &mut State) -> Result { todo!() } } impl FromState for Option { fn from_state(state: &mut State) -> Result { todo!() } }