![Latest Version] ![docs] ![MIT] [![Rust](https://img.shields.io/badge/rust-1.53%2B-blue.svg?maxAge=3600)](https://github.com/ralfbiedert/interoptopus) Rust

Interoptopus

C#, Python, C, ... → 🐙 → 🦀

FFI from your favorite language to Rust. Escape hatchets included. 🪓

Overview

If you ...

... then Interoptopus might be for you.

Known Limitations

Rust Code You Write

This is code you would write:

```rust use interoptopus::{ffifunction, ffitype};

[ffi_type]

[repr(C)]

pub struct Vec3 { pub x: f32, pub y: f32, pub z: f32, }

[ffi_function]

[no_mangle]

pub extern "C" fn my_function(input: Vec3) -> Vec3 { Vec3 { x: 2.0, y: 4.0, z: input.z } }

interoptopus::inventoryfunction!(ffiinventory, [], [my_function], []); ```

Generated Code

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! | - |

Features

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.

Current Status

FAQ

Contributing

PRs are welcome.