Skip to content

Rust FFI guide covering calling C with bindgen, exporting Rust with cbindgen, and safe wrappers.

CCM score
68 of 100
skills.sh installs
713
GitHub stars
303
last updated
Aug 21, 2026
View on GitHub

Own this skill? Claim it

What it does

  • Covers calling C from Rust, generating bindings with bindgen, exporting Rust to C with cbindgen, and writing safe wrappers around unsafe FFI
  • Includes manual extern declarations, a build.rs bindgen setup, a sys crate layout, and a cbindgen export example
  • Shows #[unsafe(no_mangle)] and unsafe extern spellings required by edition 2024, with minimum bindgen and cbindgen versions
  • Designed for Rust developers linking system or vendor C libraries, with pkg-config detection and vendored-source fallback

Install

$ npx -y skills add mohitmishra786/low-level-dev-skills --skill rust-ffi -y

Installs into .agents/skills for every agent it finds here, and .claude/skills for Claude Code.

Files

Rust FFI

Purpose

Guide agents through Rust's Foreign Function Interface: calling C from Rust with bindgen, exporting Rust to C with cbindgen, writing safe wrappers, linking libraries via build.rs, and structuring sys crates.

Triggers

  • "How do I call a C library from Rust?"
  • "How do I use bindgen to generate Rust bindings?"
  • "How do I export Rust functions to be called from C?"
  • "How do I write a safe wrapper around an unsafe C API?"
  • "How do I link a system library in Rust?"
  • "What is a sys crate and how do I structure one?"

Workflow

1. Calling C without bindgen (manual declarations)

// Declare external C functions manually
use std::ffi::{c_int, c_char, c_void, CStr, CString};

// `unsafe extern` is required in edition 2024 (and accepted since Rust 1.82)
unsafe extern "C" {
    fn strlen(s: *const c_char) -> usize;
    fn malloc(size: usize) -> *mut c_void;
    fn free(ptr: *mut c_void);
    fn my_lib_init(config: *const c_char) -> c_int;
    fn my_lib_process(handle: *mut c_void, data: *const u8, len: usize) -> c_int;
    fn my_lib_cleanup(handle: *mut c_void);
}

Details

Repository
github.com/mohitmishra786/low-level-dev-skills
Category
Rust
First seen
Jun 3, 2026

Questions

What does the rust-ffi skill help an agent do?

The rust-ffi skill guides an agent through Rust's Foreign Function Interface, covering calls from Rust into C with bindgen, exports from Rust to C with cbindgen, and safe wrappers around unsafe FFI code. It also explains linking system and vendor libraries through build.rs and structuring sys crates.

How do I install the rust-ffi skill?

Run npx -y skills add mohitmishra786/low-level-dev-skills --skill rust-ffi -y in your project. Once installed, rust-ffi lets the agent answer questions about bindgen, cbindgen, extern "C" and sys crates.

Where does rust-ffi stand among Rust skills on Claude Marketplaces?

rust-ffi ranks in the top 100 on the Rust category page on Claude Marketplaces. It focuses on C interoperability, including bindgen and cbindgen configuration and writing safe wrappers around unsafe C APIs.

Can rust-ffi generate bindings to a C library with bindgen?

Yes, rust-ffi shows how to call bindgen from a build.rs script with allowlists, derive options and rerun triggers. It also covers the sys crate layout, where pkg-config is tried first and vendored C source is compiled as a fallback.

More from mohitmishra786/low-level-dev-skills

All 54

Similar to Rust Ffi

More Rust