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

The polyglot bindings generator for your library.

Code you write ...

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

[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); }

inventory!(ffiinventory, [], [myfunction], [], []);

```

... Interoptopus generates

| Language | Crate | Sample Output | | --- | --- | --- | | C# | interoptopusbackendcsharp | Interop.cs | | C | interoptopusbackendc | myheader.h | | Python1 | interoptopusbackendcpythoncffi | reference.py | | Other | Write your own backend2 | - |

1 Using Python CFFI.
2 Create your own backend in just a few hours. No pull request needed. Pinkie promise.

Getting Started 🍼

If you want to ... - create a new API see the hello world, - understand what's possible, see the reference project, - support a new language, copy the C backend.

Features

Gated behind feature flags, these enable:

Supported Rust Constructs

See the reference project for an overview: - functions (extern "C" functions and delegates) - types (composites, enums, opaques, references, ...) - constants (primitive constants; results of const evaluation) - patterns (ASCII pointers, options, slices, classes, ...)

Performance 🏁

Generated low-level bindings are "zero cost" w.r.t. hand-crafted bindings for that language.

That said, even hand-crafted bindings encounter some target-specific overhead at the FFI boundary (e.g., marshalling or pinning in managed languages) For C# that cost can be nanoseconds, for Python CFFI it can be microseconds.

See this C# call-cost table🔥 for ballpark figures.

Changelog

Also see our upgrade instructions.

FAQ

Contributing

PRs are welcome.