Crust
C/C++ to Rust transpiler
Install / Use
/learn @NishanthSpShetty/CrustREADME
CRUST
C/C++ to Rust Transpiler
CRUST is a command-line transpiler that converts C/C++ syntax into Rust code. It aims to reduce migration effort while preserving semantics with safe, auditable output.
Highlights
- Converts declarations, assignments, and basic expressions
- Supports control flow:
if/if-else,while,for,switch - Handles basic struct/union/class definitions
- Preserves comments and outputs warning markers for unsupported constructs
- Strict (
-s) vs loose mode (default) semantics for variable mutability
Works best for small/medium C++ code slices. Complex constructs (templates, macros, function pointers) are partially supported and may require manual adjustments.
Quick Start
1) Install Rust
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
source $HOME/.cargo/env
rustc --version
2) Clone the repository
git clone https://github.com/nishanthspshetty/crust.git
cd crust
3) Build
cargo build
4) Run
cargo run -- examples/prog.cpp
Interactive prompts:
Enter the C/C++ file to be converted to Rust : examples/prog.cppEnter the translation mode [(S/s)trict/(L/l)oose] : lDo you want to create a cargo project :[Y/N] n
Output is written to examples/prog.rs by default (or <project>/src/main.rs if project creation is selected).
CLI Options
cargo run -- -s -p myproj examples/main.cpp
-s,--strict: strict mode (immutable bindings)-p,--project-name: create a new Cargo project and write toproject/src/main.rs-h,--help: display usage information
Testing
Run the full test suite:
cargo test
Key test locations:
src/library/parser/parser_test.rssrc/library/lexer/tokenizer/*
Recent test additions
- full expression output validation for declarations and expressions
- parser bounds-safe checks to avoid index panics
- strict/loose mode behavior tests
Developer Documentation
Architecture
src/main.rs: CLI + orchestration + file I/Osrc/library/lexer: tokenization pipelinesrc/library/parser: recursive descent translation engine
Parser flow
- Tokenize input into
Vec<Token> init_parserprocesses withParserstateparse_programdispatches to specialized handlers (control flow, types, assignments)- Build Rust token stream and output text
Coding standards
- avoid
Veccloning; use&[Token]slices - avoid
expectin parser production paths; useResultwith structured errors next - enforce
cargo fmt,cargo clippy
Local dev workflow
cargo test
cargo fmt --all
cargo clippy -- -D warnings
Supported Features
- Types:
int,float,char,const,unsigned, pointers - Control structures:
if,if-else,while,for,switch typedef,struct,union,class,enum- Comments preserved (as
//or/* */blocks)
Limitations
- templates, generic C++ constructs
- function pointers and functors
- macros with preprocessor logic
- comprehensive standard library conversion (e.g., iostream / std::vector)
Release Notes (latest)
- fixed Cargo metadata (
excludein[package]) - enabled robust parser bounds safety
- added full-expression tests for parser outputs
- expanded README with user + developer details, badges, screenshot placeholder
Contributing
- Fork repository
- branch:
feature/<name> - Add/update tests in
src/library/parser/parser_test.rs cargo testandcargo fmt- PR with summary of behavior regressions/improvements
License
MIT
Related Skills
himalaya
339.3kCLI to manage emails via IMAP/SMTP. Use `himalaya` to list, read, write, reply, forward, search, and organize emails from the terminal. Supports multiple accounts and message composition with MML (MIME Meta Language).
node-connect
339.3kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
83.9kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
coding-agent
339.3kDelegate coding tasks to Codex, Claude Code, or Pi agents via background process
