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
I ran into an annoying issue with BoxDynFnMut1 and friends when you try to pass around a struct with a non-'static lifetime due to the lack of higher-kinded types.
Basically, I want to let users set their own logging function. In normal Rust you'd write something like this:
Obviously for<'a> SomeStruct isn't valid syntax and you get an "Error: expected trait, found struct BoxDynFnMut1" error, however without the for<'a> you get "Error: cannot infer an appropriate lifetime due to conflicting requirements" when you try to use it in practice.
This is a concrete example of the "improve support for closures" mentioned in #47.
The text was updated successfully, but these errors were encountered:
Indeed! FWIW, there is already support for higher-ranked function pointers (stateless), which can test with the ditto internal branch:
#[derive_ReprC]// Both these attrs will likely become `#[safer_ffi::repr(transparent)]`#[repr(transparent)]structMyLoggerFnPointer(extern"C"fn(&log::Record<'_>),);
Btw @Michael-F-Bryan, thanks to your blogpost, there may even be a #[safer_ffi::repr(C, thin)] option 🙃
If you have suggestions ideas for these things, I'm all ears 🙂
For the specific case of closures, I could also imagine using the same #[repr(transparent)] syntax showcased above, but directly supporting the repr_c::closure::… types:
#[derive_ReprC]#[repr(transparent)]structMyLoggerClosure(
repr_c::BoxDynClosure<fn(&log::Record<'_>)>,// <- optional future syntax for the closure types);
I ran into an annoying issue with
BoxDynFnMut1
and friends when you try to pass around a struct with a non-'static
lifetime due to the lack of higher-kinded types.Basically, I want to let users set their own logging function. In normal Rust you'd write something like this:
The equivalent using
safer_ffi
would be (in theory) something like this:Obviously
for<'a> SomeStruct
isn't valid syntax and you get an "Error: expected trait, found structBoxDynFnMut1
" error, however without thefor<'a>
you get "Error: cannot infer an appropriate lifetime due to conflicting requirements" when you try to use it in practice.This is a concrete example of the "improve support for closures" mentioned in #47.
The text was updated successfully, but these errors were encountered: