Install
$ agentstack add skill-wnz99-claude-skills-clean-code-rust ✓ scanned · ✓ verified, works with Claude Code, Cursor, and more.
Security review
✓ PassedNo issues found. Passed automated security review. · v0.1.0 How review works →
- ✓ Prompt-injection patterns
- ✓ Secret / credential exfiltration
- ✓ Dangerous shell & filesystem operations
- ✓ Untrusted network calls
- ✓ Known-malicious package signatures
What it can access
- ✓ Network access No
- ✓ Filesystem access No
- ✓ Shell / process execution No
- ✓ Environment & secrets No
- ✓ Dynamic code execution No
From automated source analysis of v0.1.0. “Used” means the capability is present in the source — more access means more to trust, not that it’s unsafe.
Verified badge
Passed review? Show it. Paste this badge into your README, it links to the public security report.
Reliability & compatibility
Declared compatibility
Compatibility is declared by the source manifest. End-to-end runtime verification is coming, see below.
We're building live execution health for every listing: tool-call success rate, median latency, uptime, and last-checked timestamps, measured, not self-reported. It isn't live yet, so we don't show numbers we can't stand behind.
How agent discovery & health will work →About
Clean Code for Rust
Inspired by Clean Code by Robert C. Martin (Robert Cecil Martin), adapted for AI-agent use in idiomatic Rust codebases.
Use this skill to make Rust code more idiomatic, more readable, and safer to change while respecting the existing crate's conventions and API boundaries.
This skill should help an agent improve code structure without erasing useful explicitness that Rust intentionally makes visible.
Canonical source and updates
This skill is maintained in wnz99/llm-dev-skills. When asked to update, reinstall, download, or replace this skill with a newer version, inspect that upstream directory first and use the newest compatible version. Preserve intentional installation-specific adaptations and report any divergence instead of silently overwriting it.
Use This Skill When
- The user asks for cleaner Rust code, refactoring, or maintainability improvements
- A review task should include design and ergonomics findings, not just correctness bugs
- Ownership, borrowing, error handling, or type design are making the code harder to evolve
- A local refactor can materially simplify the code without changing behavior
Do Not Use This Skill When
- The task is mainly to fix behavior and a cleanup rewrite would expand scope
- The existing crate already follows a coherent internal style
- The "cleanup" would hide ownership or error behavior that should stay explicit
- The refactor would introduce abstraction layers that are larger than the problem
Operating Rules
- Read local crate conventions first.
Check Cargo.toml, formatting, lint settings, error libraries, and nearby module patterns before applying generic advice.
- Prefer explicit correctness over abstract neatness.
Rust is allowed to be explicit when that protects invariants.
- Borrow by default, but not dogmatically.
Avoid ownership churn when a borrow works; take ownership when the API genuinely needs it.
- Make the type system do useful work.
Use types to prevent mistakes when the domain boundary justifies it.
- Keep refactors local.
Do not redesign the crate unless the user asked for that.
Workflow
1. Identify the concrete problem
Typical smells:
- unnecessary clones
- weak ownership boundary
- confusing
Result/Optionflow - stringly typed domain concepts
- overgrown functions mixing validation, transformation, and I/O
- panic-based handling in a place that should return errors
match/ branching structure that obscures the real state machine
2. Check local patterns
Inspect nearby code for:
- whether the crate is app code or library code
- error strategy:
thiserror,anyhow, custom enums, or something else - public API surface and documentation expectations
- iterator-heavy vs imperative local style
- whether
Arc,Rc, builders, newtypes, or enums are already common patterns
3. Pick the smallest meaningful refactor
Good refactors:
- replace an unnecessary owned parameter with a borrow
- remove a clone by restructuring lifetimes or data flow
- split parsing / validation / side effects
- introduce an enum or newtype where raw primitives are too weak
- replace
unwrapwith structured propagation where the boundary requires it - flatten nested
if let/matchwhenlet-elseor helper methods improve readability
Avoid:
- forcing iterator chains when a loop is clearer
- hiding all branching behind traits prematurely
- introducing builders or wrapper types for one local function call
- replacing explicit, correct Rust with "cleaner" but less obvious control flow
4. Verify the boundary
After refactoring, check:
- ownership still matches how callers use the API
- error types still fit the crate boundary
- public behavior and visibility are unchanged unless intended
cargo fmt,cargo clippy, and relevant tests still pass
Rust Heuristics
Naming and API Shape
- Use domain names, not implementation placeholders
- Avoid stuttering when the module already provides context
- For getters, prefer
name()overget_name()unlessget_is the local convention or the API semantics justify it
Ownership
- Prefer
&stroverString,&[T]overVec, and&Path/impl AsRefoverPathBufwhen ownership is unnecessary - Before using
.clone(), ask whether the API boundary is wrong or whether shared ownership should be explicit - Use
Arc/Rcwhen ownership is genuinely shared, not as a reflex
Types
- Use enums when states are mutually exclusive
- Use newtypes when raw primitives are easy to mix up
- Do not create wrapper types unless they meaningfully protect the domain or clarify the API
Error Handling
- In library-like boundaries, prefer
Resultoverpanic!/unwrap()for expected failures - In app code, follow the crate's chosen error surface;
anyhow-style context may be appropriate - Keep
Optionfor absence andResultfor failure when the distinction matters - Do not stringify errors early if callers benefit from structured information
Control Flow
- Prefer the clearest form, not the shortest one
- Use
let-else, helper methods, or focused helpers when they flatten noise - Use iterators when they improve readability; keep loops when they are easier to follow
- Prefer exhaustive
matchon known enums when future variants matter
Documentation and Comments
- Document public APIs when the crate expects it or the behavior is non-obvious
unsafeblocks should always explain the safety invariant- Comments should explain why, invariants, or tricky tradeoffs, not narrate obvious code
Review Checklist
- Is ownership obvious at the API boundary?
- Are there clones that exist only to satisfy the current structure?
- Is the error surface appropriate for app code vs library code?
- Did the refactor improve readability without hiding important state transitions?
- Did the new types earn their weight?
References
Read [references/patterns.md](references/patterns.md) when you need concrete Rust cleanup patterns and examples.
Source & license
This open-source skill is cataloged on AgentStack and links to its original source — we do not rehost the code.
- Author: wnz99
- Source: wnz99/llm-dev-skills
- License: MIT
Install and usage instructions live in the source repository linked above.
Reviews
No reviews yet, be the first.
Write a review
Versions
- v0.1.0 Imported from the upstream source.