#[derive(Copy, Clone)] pub struct ValueGetterCallback(CallbackPtr); impl Callback for ValueGetterCallback { type CallbackFunc = unsafe extern "C" fn( CallbackPtr, state: FfiValueMut, object: FfiValueRef, ) -> RuntimeFuture>; } pub trait IntoPluginValueGetter { unsafe extern "C" fn get_value( callback: CallbackPtr, state: FfiValueMut, object: FfiValueRef, ) -> RuntimeFuture>; fn callback_ptr(&self) -> CallbackPtr; } impl IntoPluginValueGetter for F where Fut: Future>> + Send + Sync, S: Clone + Send + Sync + 'static, O: GiteratedObject + 'static, V: GiteratedObjectValue + Send + Sync + 'static, F: Fn(S, O) -> Fut + Send + Sync + 'static, { unsafe extern "C" fn get_value( callback: CallbackPtr, state: FfiValueMut, mut object: FfiValueRef, ) -> RuntimeFuture> { // let _guard = trace_span!( // "get_value handler", // object = O::object_name(), // value = V::value_name() // ) // .entered(); // let state = unsafe { state.transmute_ref::() }; // let object = unsafe { object.transmute_owned::() }; // // Cast the callback ptr to ourselves // let callback: *const F = std::mem::transmute(callback.0); // let callback = callback.as_ref().unwrap(); // let state = state.clone(); // runtime_state.spawn_future(async move { // let result = callback(state, *object).await; // match result { // Ok(success) => unsafe { Ok(NewAnyValue::new(success)) }, // Err(err) => match err { // OperationError::Operation(_) => todo!(), // OperationError::Internal(_) => todo!(), // OperationError::Unhandled => todo!(), // }, // } // }) todo!() } fn callback_ptr(&self) -> CallbackPtr { todo!() // unsafe { CallbackPtr::from_raw(self as *const _ as *const ()) } } } pub struct ValueChangeCallback(CallbackPtr); impl Callback for ValueChangeCallback { type CallbackFunc = unsafe extern "C" fn( &PluginState, object: FfiValueRef, value_name: FfiSliceRef, new_value: Value, ) -> RuntimeFuture<()>; } pub trait IntoValueChangeCallback { unsafe extern "C" fn value_changed( callback: CallbackPtr, state: FfiValueMut, object: FfiValueRef, value_name: FfiSliceRef, new_value: Value, ) -> RuntimeFuture<()>; } impl IntoValueChangeCallback for F { unsafe extern "C" fn value_changed( callback: CallbackPtr, state: FfiValueMut, _object: FfiValueRef, _value_name: FfiSliceRef, _new_value: Value, ) -> RuntimeFuture<()> { todo!() } }