Expand description
Core library for AST-aware Rust refactoring. Re-exports operations, editor, diff, surgical edits, and state management.
Re-exports§
pub use editor::RustEditor;pub use diff::generate_unified_diff;pub use diff::print_diff;pub use diff::print_summary_diff;pub use diff::DiffStats;pub use surgical::Replacement;pub use surgical::apply_surgical_edits;pub use operations::*;pub use state::*;
Modules§
- commands
- Per-command lib API: each subcommand of the rs-hack CLI is exposed here as
pub fn run(args: …Args) -> Result<…Result>so embedders (MCP server, yah, tests) can drive the same logic without shelling out. The CLI inmain.rsis a thin clap → struct →run()translator that adds rendering on top. - diff
- Unified diff generation and display for showing changes before applying them (dry-run mode).
- editor
- The RustEditor is the core engine of rs-hack. It parses Rust source into a syn AST, applies refactoring operations (add/remove/rename/update), and emits modified code via surgical edits or prettyplease reformatting.
- execute
- Silent execution of an
Operationacross a set of files. Returns a structuredExecuteResultwith everything a caller needs to render output, make decisions, or surface errors. Noprintln!/eprintln!— embedders (MCP server, yah, tests) decide what to display; the CLI inmain.rswraps these calls with its own renderer. - files
- File discovery: glob/dir traversal and exclusion filtering for
.rsfiles, plus the kind→node-type expansion used byfindand friends. - operations
- Data types for all refactoring operations: add, remove, rename, update, transform, and batch. Defines EditMode, BackupNode, and the operation result types.
- path_
resolver - Path resolution for safely matching qualified paths in Rust code. Tracks use statements and validates whether a path refers to a specific target.
- state
- State management: tracks run history with unique IDs, stores backup nodes for revert, and manages the .hack/rs state directory.
- surgical
- Surgical edit engine: applies precise, minimal text replacements to source code while preserving all formatting, comments, and whitespace.
- visitor
- AST visitor that walks syn trees to collect node matches (structs, enums, functions, match expressions).