プロジェクト
概要
C/C++ to Rust transpiler
言語・ランタイムできること
- 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
計測したスター増加
- 24時間
- 0
- 7日間
- 0
- 15日間
- 0
- 1か月
- 履歴を収集中
期間ごとの純増数です。期間は重複しており、日別の値ではありません。未計測の値は空欄です。スター数は注目度の指標であり、品質の保証ではありません。
README.md
オリジナル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
関連プロジェクトを探す
読み込み中…