huiali/rust-skills/rust-ffi
Claude Code and agent skill by huiali/rust-skills
Trust tier 3
- community
- ext:[{"type":"plugin","description":"Custom plugin integration"}]
Source check pending
Checking that the SKILL.md file is still in the repository.
FFI cross-language interop expert covering C/C++ bindings, bindgen, cbindgen, PyO3, JNI, memory layout, data conversion, and safe FFI patterns.
Install
npx vskill@latest install huiali/rust-skills/rust-ffiSemi-extensibleMentions customization, but needs skill-specific knowledge. Read the extensible skills standard
SKILL.md
Binding Generation
C/C++ → Rust (bindgen)
Rust → C (cbindgen)
Solution Patterns
Pattern 1: Calling C Functions
Pattern 2: String Passing
Pattern 3: Callback Functions
Pattern 4: C++ Interop with cxx
Data Type Mapping
| Rust | C | Notes | |
|---|---|---|---|
i32 | int | Usually matches | |
i64 | long long | Platform-dependent | |
usize | uintptr_t | Pointer-sized | |
*const T | const T* | Read-only | |
*mut T | T* | Mutable | |
&CStr | const char* | UTF-8 guaranteed | |
CString | char* | Ownership transfer | |
NonNull<T> | T* | Non-null pointer | |
Option<NonNull<T>> | T* (nullable) | Nullable pointer |
Error Handling
C Error Codes
Panic Across FFI
C++ Exceptions
Memory Management
| Scenario | Who Frees | How | |
|---|---|---|---|
| C allocates, Rust uses | C | Don't free from Rust | |
| Rust allocates, C uses | Rust | C notifies when done | |
| Shared buffer | Agreed protocol | Document clearly |
Workflow
Step 1: Choose FFI Strategy
Step 2: Define Safety Invariants
Step 3: Build Safe Wrapper
Step 4: Test Thoroughly
Language-Specific Tools
| Language | Tool | Use Case | |
|---|---|---|---|
| Python | PyO3 | Python extensions | |
| Java | jni | Android/JVM | |
| Node.js | napi-rs | Node.js addons | |
| C# | csharp-bindgen | .NET interop | |
| Go | cgo | Go bridge | |
| C++ | cxx | Safe C++ FFI |
Common Pitfalls
| Pitfall | Consequence | Avoid By | |
|---|---|---|---|
| String encoding error | Garbled text | Use CStr/CString | |
| Lifetime mismatch | Use-after-free | Clear ownership | |
| Cross-thread non-Send | Data race | Arc + Mutex | |
| Fat pointer to C | Memory corruption | Flatten data | |
| Missing #[no_mangle] | Symbol not found | Explicit export | |
| Panic across FFI | UB | catch_unwind |
Review Checklist
When reviewing FFI code:
- [ ] All extern functions have SAFETY comments
- [ ] String conversion uses CStr/CString properly
- [ ] Memory ownership is clearly documented
- [ ] No panics across FFI boundary (use catch_unwind)
- [ ] FFI types use #[repr(C)]
- [ ] Raw pointers validated before dereferencing
- [ ] Functions exported with #[no_mangle]
- [ ] Callbacks have correct ABI (extern "C")
- [ ] Tested with Miri for UB detection
- [ ] Documentation explains ownership protocol
Verification Commands
Safety Guidelines
- Minimize unsafe: Only wrap necessary C calls
- Defensive programming: Check null pointers, validate ranges
- Clear documentation: Who owns memory, who frees it
- Test coverage: FFI bugs are extremely hard to debug
- Use Miri: Detect undefined behavior early
Related Skills
- rust-unsafe - Unsafe code fundamentals
- rust-ownership - Memory and lifetime management
- rust-coding - Export conventions
- rust-performance - FFI overhead optimization
- rust-web - Using FFI in web services
Localized Reference
- Chinese version: SKILL_ZH.md - 完整中文版本,包含所有内容
Security
- Security scanPassed, 95 of 100Pattern checks on the skill's files.
- Model reviewPassed
- semgrepPassed, 100 of 100
- njsscanPassed, 100 of 100
- trufflehogPassed, 100 of 100
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/rust-ffi/SKILL.md
Popularity
- Repository stars
- 20
- Repository forks
- 4
- 7-day trend score
- 15
Stars and forks are for the whole GitHub repository, not this skill alone. Refreshed 21 Mar 2026, 7 months ago.
Extension points
pluginCustom plugin integration
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/huiali/rust-skills/rust-ffi)