port-c-module
Provides a systematic workflow for migrating C modules into Rust safely.
Install
mkdir -p .claude/skills/port-c-module && curl -L -o skill.zip "https://agentskills.codes/api/skills/download/2684" && unzip -o skill.zip -d .claude/skills/port-c-module && rm skill.zipInstalls to .claude/skills/port-c-module
Activation
This is the description your AI agent reads to decide when to run this skill — the better it matches your request, the more reliably it fires.
Guide for porting a C module to Rust. Use this when starting to port a C module to Rust.Key capabilities
- →Analyze C header and source files
- →Create Rust crates for ported modules
- →Implement FFI wrappers for C compatibility
- →Generate migration plans
- →Verify parity with existing C tests
How it works
It guides the user through analyzing C code, creating a Rust crate, implementing logic, and establishing an FFI boundary for integration.
Inputs & outputs
When to use port-c-module
- →Migrating C codebase to Rust
- →Analyzing C header exposure
- →Planning FFI implementations
About this skill
Port Module Skill
Guide for porting a C module to Rust.
Arguments
The module name to port should be provided as an argument (e.g., /port-module triemap).
Module to port: $ARGUMENTS
Usage
Use this skill when starting to port a C module to Rust.
Instructions
1. Analyze the C Code
First, understand the C module you're porting (look for $ARGUMENTS.c and $ARGUMENTS.h in src/):
- Read the
.cand.hfiles insrc/ - Identify what is exposed by the header file:
- Does the rest of the codebase have access to the inner fields of the data structures defined in this module?
- Are types always passed by value or by reference? A mix?
- Can the corresponding Rust types be passed over the FFI boundary?
- Understand data structures and their lifetimes
- Identify which types and functions this module imports from other modules:
- Determine if those types are implemented in Rust or C
- If those types are implemented in Rust, identify the relevant Rust crate
- If those types are implemented in C, understand if it makes sense to port them first to Rust or if it's preferable to invoke the C implementation from Rust via FFI
- Note any global state or Redis module interactions
- Identify which tests under
tests/are relevant to this module
2. Define A Porting Plan
Create a $ARGUMENTS_plan.md file to outline the steps and decisions for porting the module.
Determine if the C code should be modified, at this stage, to ease the porting process.
For example:
- Introduce getters and setters to avoid exposing inner fields of data structures defined in this module.
- Split the module into smaller, more manageable parts.
3. Create the Rust Crate
cargo new src/redisearch_rs/$ARGUMENTS --lib
4. Implement Pure Rust Logic
- Create idiomatic Rust code
- Add comprehensive tests
- Ensure that all C/C++ tests have equivalent Rust tests
- Document public APIs with doc comments
- For performance sensitive code, create microbenchmarks using
criterion - Use
proptestfor property-based testing where appropriate - Testing code should be written with the same care reserved to production code
5. Compare Rust API with C API
- Review the public API of the new Rust module against the C API in the header file
- Ensure that differences can be bridged by adding appropriate wrappers or adapters
- Go back to step 1 if discovered differences cannot be bridged without a re-design
6. Create FFI Wrapper
Create an FFI crate to expose the new Rust module to the C codebase:
cargo new src/redisearch_rs/c_entrypoint/${ARGUMENTS}_ffi --lib
FFI crate should:
- Expose
#[unsafe(no_mangle)] pub extern "C" fnfunctions - Handle null pointers and error cases
- Convert between C and Rust types safely
- Document all unsafe blocks with
// SAFETY:comments
7. Wire Up C Code
- Delete the C header file and its implementation
- Update the rest of the C codebase to import the new Rust header wherever the old C header was used
C header files for Rust FFI crates are auto-generated. No need to use their full path in imports,
use just their name (e.g. #include $ARGUMENTS.h; for ${ARGUMENTS}_ffi)
8. Test The Integration
./build.sh RUN_UNIT_TESTS # C/C++ unit tests
./build.sh RUN_PYTEST # Integration tests
Example: Well-Ported Module
See src/redisearch_rs/trie_rs/ for a high-quality example:
- Pure Rust implementation with comprehensive docs
- Extensive test coverage
- Clean FFI boundary in
c_entrypoint/trie_ffi/
When not to use it
- →When the C module is too complex to port
- →When C performance is strictly required
Prerequisites
Limitations
- →Requires manual effort for complex data structures
- →FFI boundary requires careful safety management
How it compares
It provides a structured migration path rather than manual, ad-hoc porting.
Compared to similar skills
port-c-module side by side with the closest alternatives in the catalog.
| Skill | Installs | Updated | Safety | Difficulty |
|---|---|---|---|---|
| port-c-module (this skill) | 2 | 2mo | Review | Advanced |
| arm-cortex-expert | 29 | 4mo | No flags | Advanced |
| compiler-development | 1 | 6mo | No flags | Advanced |
| memory-safety-patterns | 4 | 4mo | No flags | Advanced |
Try saying
Example prompts that trigger this skill in your AI assistant.
More by RediSearch
View all by RediSearch →You might also like
arm-cortex-expert
sickn33
Senior embedded software engineer specializing in firmware and driver development for ARM Cortex-M microcontrollers (Teensy, STM32, nRF52, SAMD). Decades of experience writing reliable, optimized, and maintainable embedded code with deep expertise in memory barriers, DMA/cache coherency, interrupt-driven I/O, and peripheral drivers.
compiler-development
gmh5225
Expertise in compiler development using LLVM infrastructure including frontend design, IR generation, optimization passes, and code generation. Use this skill when building custom programming languages, implementing DSL compilers, or working on compiler internals.
memory-safety-patterns
sickn33
Implement memory-safe programming with RAII, ownership, smart pointers, and resource management across Rust, C++, and C. Use when writing safe systems code, managing resources, or preventing memory bugs.
debug-lldb
regenrek
Capture and analyze thread backtraces with LLDB/GDB to debug hangs, deadlocks, UI freezes, IPC stalls, or high-CPU loops across any language or project. Use when an app becomes unresponsive, switching contexts stalls, or you need thread stacks to locate lock inversion or blocking calls.
server-tick
dadbodgeoff
Server-authoritative tick system for multiplayer games with lag compensation, anti-cheat validation, and deterministic physics. Prevents speed hacks and teleports while keeping gameplay fair for high-latency players.
deepwiki-rs
sopaco
AI-powered Rust documentation generation engine for comprehensive codebase analysis, C4 architecture diagrams, and automated technical documentation. Use when Claude needs to analyze source code, understand software architecture, generate technical specs, or create professional documentation from any programming language.