You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The idea is to wrap up the pointer and length of an array that's only valid for the duration of a given API call, and is expected to be an array of T (where T is some FFI-safe value). The lifetime 'a and type T are there to enforce those rules throughout the Rust code, though they have no effect at the FFI boundary:
When I use cbindgen to generate this, the FfiSlice struct is monomorphized into FfiSlice_u8, which normally makes sense but there's no need to monomorphize it at all because the layout is the same no matter the T. The T is only used in zero-sized fields within the struct. The generic parameter can be erased entirely.
Is there a way to instruct cbindgen to do this? I get that maybe it can't detect this scenario, but could there be an option to "erase" generics from a given type (at your own risk)?
The text was updated successfully, but these errors were encountered:
analogrelay
changed the title
Erasing struct generics where there are no fields using them
Erasing struct generics where there are sized fields using them
Jan 18, 2025
analogrelay
changed the title
Erasing struct generics where there are sized fields using them
Erasing struct generics where there are no sized fields using them
Jan 21, 2025
In the C API I'm building, I'd like to have this struct:
The idea is to wrap up the pointer and length of an array that's only valid for the duration of a given API call, and is expected to be an array of
T
(whereT
is some FFI-safe value). The lifetime'a
and typeT
are there to enforce those rules throughout the Rust code, though they have no effect at the FFI boundary:When I use cbindgen to generate this, the
FfiSlice
struct is monomorphized intoFfiSlice_u8
, which normally makes sense but there's no need to monomorphize it at all because the layout is the same no matter theT
. TheT
is only used in zero-sized fields within the struct. The generic parameter can be erased entirely.Is there a way to instruct cbindgen to do this? I get that maybe it can't detect this scenario, but could there be an option to "erase" generics from a given type (at your own risk)?
The text was updated successfully, but these errors were encountered: