I currently have an API that accepts Fn items. I am able to do interesting optimizations where the F in F: Fn() is a function pointer in FFI land.
Partial list of optimizations I can do with function pointers:
- No special drop handling.
- No vtable lookups.
- No heap allocation to store the
Fnitem. (currently required to box them for safety because reasons) - 2 pointer indirections instead of 3.
- Not really important but less overall space used since an
fnpointer is smaller than aBox<dyn Fn()>
How can I go about this without exposing different API's for function pointers and Fn items?