rust-ffi-bindings

Create safe Rust FFI bindings with #[repr(C)] structs and extern "C exports across multiple targets.

1|2|Updated Dec 10, 2025
One-click install
npx skills add https://github.com/Glubus/Rhythm-Open-Exchange --skill rust-ffi-bindings
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: rust-ffi-bindings
Source: https://github.com/Glubus/Rhythm-Open-Exchange/tree/main/.agent/skills/rust-ffi-bindings
Command: npx skills add https://github.com/Glubus/Rhythm-Open-Exchange --skill rust-ffi-bindings

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill helps Rust developers design safe, portable FFI bindings to expose Rust libraries to other languages by enforcing boundary safety, ABI-stable layouts, and clear ownership semantics.

Core Features & Use Cases

  • Safety at the boundary: catch panics, validate inputs, and prevent undefined behavior when crossing language boundaries.
  • ABI stability: use #[repr(C)] on exported types and stable enums to ensure consistent memory layouts across languages.
  • Memory ownership & error handling: define explicit ownership models and robust error codes to communicate failures across FFI.
  • Binding patterns for multiple targets: C API exports, C# bindings, Python bindings (PyO3), WebAssembly bindings (wasm-bindgen), and UniFFI multi-language bindings.
  • Use cases: expose a Rust core (e.g., chart data structures) to C, Python, and JS environments for broader integration.

Quick Start

Install the Rust toolchain, annotate your exported APIs with extern "C" and #[repr(C)], implement panic-safety wrappers, and generate or wire up bindings with UniFFI, wasm-bindgen, or CsBindgen as needed.

Frequently Asked Questions about rust-ffi-bindings

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I create safe Rust FFI bindings for a C API?▼

Safe Rust FFI bindings require enforcing boundary safety with extern "C" exports, #[repr(C)] types, panic catching, and explicit ownership semantics to prevent undefined behavior across languages.

How does Rust handle memory ownership and errors when exporting to Python?▼

Rust handles memory ownership and errors in Python bindings by defining explicit ownership models and robust error codes, ensuring safe data layout and failure communication across the FFI boundary.

Can I use UniFFI to generate Rust bindings for multiple languages?▼

Yes, UniFFI generates multi-language Rust bindings, allowing you to expose a Rust core to C, Python, and WebAssembly targets using ABI-stable exports and consistent memory layouts.

What's the best way to expose Rust library functions to WebAssembly?▼

Exposing Rust library functions to WebAssembly uses wasm-bindgen to wire up bindings, applying #[repr(C)] layouts and panic-safety wrappers to ensure stable, safe cross-language integration.

Why do Rust FFI calls cause undefined behavior and how do I prevent it?▼

Rust FFI calls cause undefined behavior when panics cross boundaries or data layouts are unstable; prevent it by catching panics, validating inputs, and using #[repr(C)] for ABI stability.

Do I need to use repr C for all exported Rust types in FFI?▼

Yes, using #[repr(C)] on exported Rust types in FFI is required to ensure ABI-stable memory layouts, preventing inconsistent data representation across C, C#, Python, and WebAssembly targets.