use std::ffi::c_void;
pub unsafe trait FnPtr: Copy + Send + Sync + 'static {
fn into_raw(self) -> *mut c_void;
unsafe fn from_raw(raw: *mut c_void) -> Self;
}
macro_rules! fn_ptr {
($($arg:ident),*) => {
unsafe impl<R: 'static, $($arg: 'static),*> FnPtr for unsafe extern "C" fn($($arg),*) -> R {
fn into_raw(self) -> *mut c_void {
self as *const () as *mut c_void
}
unsafe fn from_raw(raw: *mut c_void) -> Self {
unsafe { std::mem::transmute_copy::<*mut c_void, Self>(&raw) }
}
}
};
}
fn_ptr!();
fn_ptr!(A);
fn_ptr!(A, B);
fn_ptr!(A, B, C);
fn_ptr!(A, B, C, D);
fn_ptr!(A, B, C, D, E);
fn_ptr!(A, B, C, D, E, F);
fn_ptr!(A, B, C, D, E, F, G);
fn_ptr!(A, B, C, D, E, F, G, H);
fn_ptr!(A, B, C, D, E, F, G, H, I);
fn_ptr!(A, B, C, D, E, F, G, H, I, J);
fn_ptr!(A, B, C, D, E, F, G, H, I, J, K);
fn_ptr!(A, B, C, D, E, F, G, H, I, J, K, L);