use crate::dynamic_data::Event; use crate::ffi::BorrowedPtr; /// Wrapper class for easier use of an external function pointer. #[repr(C)] pub(super) struct NativeEventHook { /// The actual C function to be called. f: extern "C" fn(BorrowedPtr), } impl NativeEventHook { /// Calls the actual wrapped function in the correct format. fn call_self(&self, b: &&Event<'_>) { (self.f)(*b as *const Event) } } /// A tuple with the arguments of the event hook function type EventHookArgs<'a, 'b, 'c> = (&'a Box<&'b Event<'c>>,); impl FnMut> for NativeEventHook { extern "rust-call" fn call_mut(&mut self, args: EventHookArgs<'_, '_, '_>) -> Self::Output { self.call_self(args.0) } } impl FnOnce> for NativeEventHook { type Output = (); extern "rust-call" fn call_once(self, args: EventHookArgs<'_, '_, '_>) -> Self::Output { self.call_self(args.0) } } impl Fn> for NativeEventHook { extern "rust-call" fn call(&self, args: EventHookArgs<'_, '_, '_>) -> Self::Output { self.call_self(args.0) } }