Make an UnsafeExternCFn struct to overcome fn pointer hrtb

This commit is contained in:
2025-06-23 17:40:18 +10:00
parent c39106b790
commit 2352ba66d4
3 changed files with 138 additions and 154 deletions

View File

@@ -1,6 +1,7 @@
use crate::{
__internal::{display, type_id},
Cdef, CdefBuilder, FfiReturnConvention, Metatype, MetatypeBuilder, ToFfi, Type, TypeBuilder,
UnsafeExternCFn,
};
use luaify::luaify;
use std::{
@@ -147,8 +148,8 @@ unsafe impl<F: Future<Output: ToFfi> + 'static> Type for lua_future<F> {
unsafe impl<F: Future<Output: ToFfi> + 'static> Cdef for lua_future<F> {
fn build(s: &mut CdefBuilder) {
s.field_opaque(mem::offset_of!(Self, take)) // opaque .sig, .poll and .state
.field::<unsafe extern "C" fn(*mut Self) -> <F::Output as ToFfi>::To>("__take")
.field::<unsafe extern "C" fn(*mut Self)>("__drop");
.field::<UnsafeExternCFn<(&mut Self,), <F::Output as ToFfi>::To>>("__take")
.field::<UnsafeExternCFn<(&mut Self,), ()>>("__drop");
}
}