Interoptopus
Create FFI bindings to your favorite language. Composable. Escape hatches included.
Overview
- you wrote an
extern "C"
API in Rust - the types at the FFI boundary are (mostly) owned by yourself
- you prefer to keep all your binding-related information (e.g., documentation) in Rust code
Known limitations
- not used in production yet
- somewhat verbose if you don't own most of your types (still possible, just more work)
- if you target only a single language and don't care about your FFI layer other solutions might be better
Supported Languages
Language | Crate | Comment |
---|---|---|
C# | interoptopus_backend_csharp |
Built-in. |
C | interoptopus_backend_c |
Built-in. |
Python CFFI | interoptopus_backend_cpython_cffi |
Built-in. |
Your language | Write your own backend! | See existing backends for what to do.* |
(*) Ok, right now I don't really recommend writing a new backend just yet as lots of internals might change. That said, it should only take a few hours and feedback is more than welcome.
Example
Slightly abridged, see the examples/hello_world
for full code:
use ;
use Interop;
/// A function which does something with the vector.
pub extern "C"
// This ultimately defines our FFI exports, all functions have to be listed here.
inventory_function!;
With a Cargo.toml:
[]
= { = "0.1", = ["derive"] }
= "0.1"
Will produce:
using ;
using ..;
For other languages (Python, C, ...) see examples
folder.