juanmarchetto/agent-skills/c-to-rust-migration

Trust tier 3
  • community
Source check pending

Checking that the SKILL.md file is still in the repository.

Complete C/C++ to Rust migration pipeline. Analyzes code difficulty, converts to idiomatic safe Rust, and validates the result. Covers memory management, pointer translation, error handling, unsafe minimization, and differential testing. Use when: migrate C to Rust, rewrite in Rust, C to Rust conversion, Rust migration, convert C code, C2Rust, unsafe Rust reduction.

Install

npx vskill@latest install juanmarchetto/agent-skills/c-to-rust-migration

SKILL.md

C to Rust Migration

Complete pipeline for migrating C/C++ codebases to safe, idiomatic Rust. Covers analysis, conversion, and validation in three phases.

Pipeline

C/C++ Source
|
Phase 1: ANALYZE
| Classify difficulty (easy/medium/hard)
| Detect patterns (pointers, macros, goto, unions)
| Plan conversion strategy
|
Phase 2: CONVERT
| Apply migration patterns
| Memory management → ownership/borrowing
| Error codes → Result<T, E>
| Pointer arithmetic → slices/iterators
| Quality gate: re-translate if >5 unsafe blocks
|
Phase 3: VALIDATE
| Compilation check (edition 2024)
| Unsafe minimization (target: 0 for easy/medium)
| Clippy with 0 warnings
| Differential testing (same I/O as original C)
| Idiomatic score calculation
|
Safe, Idiomatic Rust

Phase 1: Analysis

Classify each function by migration difficulty:

DifficultyPatternsStrategy
EasyPure functions, simple arithmetic, no pointers, <30 linesDirect translation, should produce 0 unsafe
MediumPointer parameters, simple structs, bounded arrays, malloc with clear ownershipTranslate with ownership patterns, minimize unsafe
Hardvoid*, function pointers, unions, goto, complex lifetimes, macro-heavyMay need C2Rust as starting point, then iterative cleanup

Hard signals (any one → Hard): goto, setjmp/longjmp, variadic functions, inline assembly, complex #define macros with side effects.

See references/analysis-patterns.md for the complete pattern catalog.

Phase 2: Conversion Patterns

Core translations:

C PatternRust Pattern
malloc/freeVec, Box, or stack allocation
char* strings&str, String, CStr
int error codesResult<T, Error> with thiserror
NULL checksOption<T>
Array + length paramsSlices (&[T])
void*Generics or enum dispatch
Function pointersFn traits or enum dispatch
struct with init/freeimpl with new() + Drop
Global mutable stateOnceLock, Mutex, or dependency injection
goto cleanupDrop guards or ? operator

Quality gate: If translation produces >5 unsafe blocks, re-attempt with lower temperature (0.5) focusing on the unsafe sections.

See references/conversion-patterns.md for detailed examples from real migrations.

Phase 3: Validation

Checklist (in order):

  1. Compilation: cargo build with edition 2024, zero errors
  2. Clippy: cargo clippy with zero warnings
  3. Unsafe audit: Count unsafe blocks. Every one needs a // SAFETY: comment explaining why it's sound
  4. Differential testing: Same inputs → same outputs as original C code
  5. Idiomatic score: (1 - unsafe_blocks/total_functions) * 0.4 + clippy_clean * 0.3 + has_tests * 0.2 + has_docs * 0.1

Quality floor: Never accept a version that scores lower than the current best. If a fix attempt reduces the score, discard it.

See references/validation-checklist.md for the complete validation protocol.

Example Output

C-to-Rust Migration Report — http_parser.c
Analysis:
Total functions: 23
Easy: 8 | Medium: 11 | Hard: 4
Hard patterns: 2 goto statements, 1 union, 1 function pointer dispatch
Conversion:
Functions migrated: 23/23
Unsafe blocks: 2 (both in FFI boundary — justified)
Idiomatic patterns applied: Result<T,E>, Option<T>, iterators, Drop guards
Validation:
✅ Compiles (edition 2024)
✅ Clippy: 0 warnings
✅ Unsafe: 2 blocks, both with SAFETY comments
✅ Diff tests: 47/47 passing (100%)
Idiomatic score: 0.91/1.0
Quality: EXCELLENT — ready for production use

Error Handling

  • C code doesn't compile: Need the original build system info (Makefile, CMakeLists.txt) to understand dependencies and flags
  • Too many unsafe blocks: Re-attempt conversion focusing on the unsafe sections. Consider if some are FFI boundaries (justified) vs unnecessary
  • Diff tests fail: Compare output byte-by-byte. Common causes: endianness, floating point precision, uninitialized memory in C
  • Circular dependencies: Rust doesn't allow circular module deps. Restructure with traits or merge modules

Origin

Patterns extracted from real-world C-to-Rust migrations of open-source libraries: cJSON, genann, http-parser, picohttpparser, olive.c.

Security

  • Security scanPassed, 95 of 100Pattern checks on the skill's files.
  • Model reviewPassed

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

Repository stars
5
Repository forks
1
7-day trend score
9

Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.

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
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/juanmarchetto/agent-skills/c-to-rust-migration/badge)](https://verified-skill.com/skills/juanmarchetto/agent-skills/c-to-rust-migration)

Something wrong with this skill or its page? Tell us.