2022-10-15 15:21:24 +00:00
|
|
|
use crate::dynamic_data::Event;
|
2022-11-26 10:25:56 +00:00
|
|
|
use crate::ffi::BorrowedPtr;
|
2022-10-15 15:21:24 +00:00
|
|
|
|
|
|
|
/// Wrapper class for easier use of an external function pointer.
|
|
|
|
#[repr(C)]
|
|
|
|
pub(super) struct NativeEventHook {
|
|
|
|
/// The actual C function to be called.
|
2022-11-26 10:25:56 +00:00
|
|
|
f: extern "C" fn(BorrowedPtr<Event>),
|
2022-10-15 15:21:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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<EventHookArgs<'_, '_, '_>> for NativeEventHook {
|
|
|
|
extern "rust-call" fn call_mut(&mut self, args: EventHookArgs<'_, '_, '_>) -> Self::Output {
|
|
|
|
self.call_self(args.0)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl FnOnce<EventHookArgs<'_, '_, '_>> for NativeEventHook {
|
|
|
|
type Output = ();
|
|
|
|
|
|
|
|
extern "rust-call" fn call_once(self, args: EventHookArgs<'_, '_, '_>) -> Self::Output {
|
|
|
|
self.call_self(args.0)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Fn<EventHookArgs<'_, '_, '_>> for NativeEventHook {
|
|
|
|
extern "rust-call" fn call(&self, args: EventHookArgs<'_, '_, '_>) -> Self::Output {
|
|
|
|
self.call_self(args.0)
|
|
|
|
}
|
|
|
|
}
|