This crate is for producing Rust closures that can cross an FFI boundary. It provides support for any function signature, assuming all of the types in it have valid representations in C/C++ and Rust.
*Closure by itself can not cause undefined behavior, however when the resulting
structure is used in C/C++ it can still trigger undefined behavior.
*Closure should never be
an argument to a safe function, nor should it be a public member of any structures passed into a safe function.
Please write your own safe wrappers that incorporate the
*Closure types internally.
To use this with a C/C++ library you'll need to include the header provided in the repo,
rust_closures.h. Then you can accept the relevant
*Closure type anywhere that you need to
accept arbitrary Rust code.
This cannot be used to transfer ownership of allocated memory across FFI boundaries, as this crate cannot reasonably guarantee
both sides are using the same memory allocator, or dispose of the types in the same way. If such transfer
is required, you should copy the data into a new allocation, on the side of the FFI boundary it needs to live
on. The major exception to this is types with the
Copy marker trait, which are trivially cloned and require
no disposal instructions.
Provides the path containing
Accepts a blob of auto generated rust code binding to a C/C++ library, probably from