Getting Started
This guide will help you get up and running with Refactor DSL quickly.
Overview
Refactor DSL can be used in two ways:
- As a Rust library - Integrate into your Rust projects for programmatic refactoring
- As a CLI tool - Run refactoring operations from the command line
Prerequisites
- Rust 1.70+ (for building from source)
- Git (for repository operations)
Quick Example
Here’s a simple example that replaces all .unwrap() calls with .expect():
use refactor::prelude::*;
fn main() -> Result<()> {
let result = Refactor::in_repo("./my-project")
.matching(|m| m
.files(|f| f.extension("rs")))
.transform(|t| t
.replace_pattern(r"\.unwrap\(\)", ".expect(\"TODO\")"))
.dry_run() // Preview first
.apply()?;
println!("{}", result.diff());
Ok(())
}
Or using the CLI:
refactor replace \
--pattern '\.unwrap\(\)' \
--replacement '.expect("TODO")' \
--extension rs \
--dry-run
Next Steps
- Installation - Install the library or CLI
- Quick Start - Walk through a complete example
- Matchers - Learn how to select files and code
- Transforms - Learn how to modify code