This question is inspired by the topic of How to pass a closure as an extern C function , although I have not read the entire thread. Apologies if this is redundant.
The question is interesting for C++, because C++ does have "fat pointers" for closures (
std::function). One can construct a C++ fat pointer from a C-style closure with
std::bind(C-style function pointer, C-style context pointer).
I have been writing bindings for portions of a C++ library API (on an as-needed basis), mostly by wrapping it in a C ABI, which is easy to import/FFI from Rust. But I did not find a happy way to pass a Rust closure through a C ABI and into a C++
std::function for callback. (A large part of the difficulty is determining the correct lifetime for the callback closure and embedded refs, but let's call that off-topic for the question.)
Has anyone successfully done this before? What works? Thank you.