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

Extensible, lightweight, convenient FFI bindings for any* language calling Rust.

Escape hatchets included. 🪓

* C#, C, Python provided. Add yours in 4 hours. No pull request needed.

Code you write ...

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

[ffi_type]

[repr(C)]

pub struct Vec2 { pub x: f32, pub y: f32, }

[ffi_function]

[no_mangle]

pub extern "C" fn my_function(input: Vec2) { println!("{}", input.x); }

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

... Interoptopus generates

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

Getting Started 🍼

If you ... - want to create a new API see the example projects, - need to support a new language or rewrite a backend, copy and adapt the C backend.

Features

Supported Rust Constructs

See the reference project; it 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.