![Latest Version]
![docs]
![MIT]
[](https://github.com/ralfbiedert/interoptopus)
C#, Python, C, ... → 🐙 → 🦀
FFI from your favorite language to Rust. Escape hatchets included. 🪓
If you ...
extern "C"
API in Rust,... then Interoptopus might be for you.
This is code you would write:
```rust use interoptopus::{ffifunction, ffitype};
pub struct Vec3 { pub x: f32, pub y: f32, pub z: f32, }
pub extern "C" fn my_function(input: Vec3) -> Vec3 { Vec3 { x: 2.0, y: 4.0, z: input.z } }
interoptopus::inventoryfunction!(ffiinventory, [], [my_function], []); ```
Once you've written the code above you use one of these backends to generate interop code:
| Language | Crate | Sample Output | | --- | --- | --- | | C# (incl. Unity) | interoptopusbackendcsharp | Interop.cs | | C | interoptopusbackendc | myheader.h | | Python CFFI | interoptopusbackendcpythoncffi | reference.py | | Your language | Write your own backend! | - |
See the reference project lists all supported constructs including:
- functions (extern "C"
functions and delegates)
- types (primitives, composite, enums (numeric only), opaques, references, pointers, ...)
- constants (primitive constants; results of const evaluation)
- patterns (ASCII pointers, options, slices, classes, ...)
As a rule of thumb we recommend to be slightly conservative with your signatures and always "think C", since other languages don't track lifetimes
well and it's is easy to accidentally pass an outlived pointer or doubly alias a &mut X
on reentrant functions.
PRs are welcome.
Bug fixes can be submitted directly. Major changes should be filed as issues first.
Anything that would make previously working bindings change behavior or stop compiling is a major change; which doesn't mean we're opposed to breaking stuff before 1.0, just that we'd like to talk about it before it happens.
New features or patterns must be materialized in the reference project and accompanied by an interop test (i.e., a backend test running C# / Python against a DLL invoking that code) in at least one included backend.