pub
trait ZeroSizedElseWrathOfTheGඞds : Sized {
#[doc(hidden)]
const WRATH_OF_THE_GඞDS: () = assert!(::core::mem::size_of::<Self>() == 0);
}
impl<F> ZeroSizedElseWrathOfTheGඞds for F {}
impls! {
_11, _10, _9, _8, _7, _6,
_5, _4, _3, _2, _1, _0,
}
macro_rules! impls {(
$(
$Hd:ident $(,
$Rest:ident )* $(,)? )?
) => (
$(impls! { $($Rest),* })?
impl<F, $($Hd $(, $Rest)* ,)? R>
FnExt<($($Hd, $($Rest),*)?)>
for
F
where
F : Fn($($Hd $(, $Rest)*)?) -> R,
F : 'static + Sync + ZeroSizedElseWrathOfTheGඞds,
{
type CSignature = extern "C" fn($($Hd $(, $Rest)*)?) -> R;
fn extern_c(f: Self) -> Self::CSignature {
_ = Self::WRATH_OF_THE_GඞDS;
let _leaked_into_zst_symbolic_heap = ::core::mem::forget(f);
extern "C"
fn extern_c_thunk<F, $($Hd $(, $Rest)* ,)? R>($(
$Hd: $Hd $(,
$Rest: $Rest )*)?
) -> R
where
F : Fn($($Hd $(, $Rest)*)?) -> R,
{
let out_of_thin_air: [F; 0] = [];
(unsafe {
// SAFETY:
// - conceptually, this is `SOME_GLOBAL_MAP.get(f)`
&*out_of_thin_air.as_ptr()
})(
$($Hd $(, $Rest)*)?
)
}
extern_c_thunk::<F, $($Hd $(, $Rest)* ,)? R>
}
}
)} use impls;
pub
trait FnExt<Args> : 'static + Sync + ZeroSizedElseWrathOfTheGඞds {
type CSignature;
fn extern_c(this: Self) -> Self::CSignature;
}