Loading skill
Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Review RTK Rust code for idiomatic simplification. Detects over-engineering, unnecessary allocations, verbose patterns. Applies Rust idioms without changing behavior.
| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-02 | ✗→✓ | ▲ Improved | 37% | 0% |
| case-03 | ✗→✓ | ▲ Improved | 18% | 0% |
| case-04 | ✗→✓ | ▲ Improved | 40% | 0% |
| case-05 | ✗→✓ | ▲ Improved | 9% | 0% |
| case-17 | ✗→✓ | ▲ Improved | -5% | 0% |
Review and simplify Rust code in RTK while respecting the project's constraints.
LazyLock regex — cannot be moved inside functions even if "simpler".context() on every ? — verbose but mandatoryOk(())#[cfg(test)] mod tests — never remove test modulesrust// ❌ Verbose let mut result = Vec::new(); for line in input.lines() { let trimmed = line.trim(); if !trimmed.is_empty() && trimmed.starts_with("error") { result.push(trimmed.to_string()); } } // ✅ Idiomatic let result: Vec<String> = input.lines() .map(|l| l.trim()) .filter(|l| !l.is_empty() && l.starts_with("error")) .map(str::to_string) .collect();
rust// ❌ Verbose push loop let mut out = String::new(); for (i, line) in lines.iter().enumerate() { out.push_str(line); if i < lines.len() - 1 { out.push('\n'); } } // ✅ join let out = lines.join("\n");
rust// ❌ Nested match let result = match maybe_value { Some(v) => match transform(v) { Ok(r) => r, Err(_) => default, }, None => default, }; // ✅ Chained let result = maybe_value .and_then(|v| transform(v).ok()) .unwrap_or(default);
rust// ❌ Repeated field access fn process(args: &MyArgs) -> String { format!("{} {}", args.command, args.subcommand) } // ✅ Destructure fn process(&MyArgs { ref command, ref subcommand, .. }: &MyArgs) -> String { format!("{} {}", command, subcommand) }
rust// ❌ Deeply nested fn filter(input: &str) -> Option<String> { if !input.is_empty() { if let Some(line) = input.lines().next() { if line.starts_with("error") { return Some(line.to_string()); } } } None } // ✅ Early return fn filter(input: &str) -> Option<String> { if input.is_empty() { return None; } let line = input.lines().next()?; if !line.starts_with("error") { return None; } Some(line.to_string()) }
rust// ❌ Unnecessary clone fn filter_output(input: &str) -> String { let s = input.to_string(); // Pointless clone s.lines().filter(|l| !l.is_empty()).collect::<Vec<_>>().join("\n") } // ✅ Work with &str fn filter_output(input: &str) -> String { input.lines().filter(|l| !l.is_empty()).collect::<Vec<_>>().join("\n") }
if let for single-variant matchrust// ❌ Full match for one variant match output { Ok(s) => process(&s), Err(_) => {}, } // ✅ if let (but still handle errors in RTK — don't silently drop) if let Ok(s) = output { process(&s); } // Note: in RTK filters, always handle Err with eprintln! + fallback
Run these after simplification:
bash# Verify no regressions cargo fmt --all && cargo clippy --all-targets && cargo test # Verify no new regex in functions grep -n "Regex::new" src/<file>.rs # Fixed, reused patterns should be in `LazyLock<Regex>` statics # Verify no new unwrap in production grep -n "\.unwrap()" src/<file>.rs # Should only appear inside #[cfg(test)] blocks
static RE: LazyLock<Regex> = LazyLock::new(|| Regex::new(...).unwrap()); — the .unwrap() here is acceptable, it's init-time.context("description")? chains — verbose but requiredErr(e) => { eprintln!(...); raw_output } — looks redundant but is the safety netstd::process::exit(code) at end of run() — looks like it could be Ok(())but it isn'tOther measured skills in the registry, with their headline benchmark lift.