use crate::abi;
use core::mem::MaybeUninit;
pub type Closure = (unsafe extern "C" fn(abi::EXINF), abi::EXINF);
pub trait IntoClosure {
fn into_closure(self) -> Closure;
}
impl IntoClosure for (extern "C" fn(abi::EXINF), abi::EXINF) {
#[inline]
fn into_closure(self) -> Closure {
(self.0, self.1)
}
}
impl<T: Fn() + Copy + 'static> IntoClosure for T {
#[inline]
fn into_closure(self) -> Closure {
trait AssertSize {
const X: ();
}
impl<T> AssertSize for T {
const X: () = if core::mem::size_of::<T>() > core::mem::size_of::<abi::EXINF>() {
let zero = 0;
#[allow(unconditional_panic)]
#[allow(non_snake_case)]
let __T_is_too_large_to_fit_in_EXINF__ = 1 / zero;
#[allow(clippy::empty_loop)]
loop {}
};
}
let () = <T as AssertSize>::X;
extern "C" fn trampoline<T: Fn() + Copy + 'static>(x: abi::EXINF) {
let t: T = unsafe { core::mem::transmute_copy(&x) };
t();
}
#[repr(C)]
struct PadWithZero<T> {
x: MaybeUninit<T>,
zero: MaybeUninit<abi::EXINF>,
}
(trampoline::<T>, unsafe {
core::mem::transmute_copy(&PadWithZero {
x: MaybeUninit::new(self),
zero: MaybeUninit::uninit(),
})
})
}
}