ffi-diplomat

Expose Rust types to C/C++ and WASM via Diplomat FFI bindings.

Updated Dec 10, 2025
One-click install
npx skills add https://github.com/novelsaga/NSaga --skill ffi-diplomat
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: ffi-diplomat
Source: https://github.com/novelsaga/NSaga/tree/main/.opencode/skills/ffi-diplomat
Command: npx skills add https://github.com/novelsaga/NSaga --skill ffi-diplomat

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Expose Rust types to C/C++ and WASM through a structured Diplomat FFI binding pattern. The approach reduces boilerplate and error-prone hand-written bindings across language boundaries.

Core Features & Use Cases

  • Single bridge module: All FFI definitions are centralized in one #[diplomat::bridge] module.
  • Safe opaque types: Use #[diplomat::opaque] wrappers to encapsulate internal Rust types.
  • Robust string IO: Employ DiplomatStr and DiplomatWrite for cross-language string handling.

Quick Start

Create a single #[diplomat::bridge] module that exposes the public Rust types to C/C++ and WASM.

Frequently Asked Questions about ffi-diplomat

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

FAQPage Schema
How do I expose Rust types to C/C++ and WASM without writing error-prone bindings?

You can expose Rust types to C/C++ and WASM using Diplomat to reduce boilerplate. It enforces a structured FFI binding pattern with a single #[diplomat::bridge] module and #[diplomat::opaque] wrappers to safely encapsulate internal types across language boundaries.

What is the best way to handle string IO across Rust and C/C++ language boundaries?

The best way to handle cross-language string IO is using DiplomatStr and DiplomatWrite. These mechanisms are part of the Diplomat FFI binding pattern, ensuring robust string handling when exposing Rust types to C/C++ and WASM environments.

How do I set up a Diplomat bridge module to expose Rust types?

To set up a Diplomat bridge, create a single #[diplomat::bridge] module that centralizes all FFI definitions. Within this module, apply #[diplomat::opaque] wrappers to your types and use constructor attributes to expose them to C/C++ and WASM.

Can I use Diplomat to generate WASM bindings from my existing Rust libraries?

Yes, you can use Diplomat to generate WASM bindings from Rust libraries. It specifically supports exposing Rust types to WASM alongside C/C++ by enforcing opaque wrappers and structured bridge modules, reducing hand-written binding errors.

Why should I use opaque wrappers for Rust FFI bindings instead of exposing types directly?

You should use #[diplomat::opaque] wrappers because they safely encapsulate internal Rust types when exposing them to C/C++ and WASM. This prevents direct memory access across language boundaries, reducing boilerplate and avoiding error-prone hand-written FFI bindings.

Does this Diplomat FFI pattern require multiple bridge modules for different languages?

No, the Diplomat FFI pattern enforces a single #[diplomat::bridge] module. All FFI definitions for exposing Rust types to both C/C++ and WASM are centralized in this one module, which reduces boilerplate and simplifies maintenance.