rust-clean-code
Skill0 starsChanged 2 months agoMITView on GitHub
Enforces strict architecture, readability, and scalability standards for Rust codebases. Mandates explicit approval before editing code, zero warning suppressions (no #[allow(...)]), no old mod.rs (use foldername.rs), <400 lines/file, <60 lines/fn, max 3 nesting depth, role-based architecture (domain/, infra/, api/), DRY, and zero production unwrap()/expect().
In this repository20 other files it gives its agents.
- AGENTS.mdAGENTS.md
- rules/AGENTS.mdAGENTS.md
- kurokoSkill
- tayoriSkill
- xerjSkill
- aesthetic-readme-craftSkill
- cli-builderSkill
- codebase-digestSkill
- git-release-craftSkill
- git-repo-craftSkill
- karakuriSkill
- python-clean-codeSkill
- rust-style-pythonSkill
- systematic-code-verificationSkill
- compose-clean-codeSkill
- bash-clean-codeSkill
- tui-designSkill
- frontend-designSkill
- web-design-guidelinesSkill
- unslopSkill
The file
We split this skill into the rules it gives an agent
9 rules. About 0 are common, 4 are distinctive, and 5 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈4
Distinctive · estimate
This author's own choices. Worth a look.
5
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 24
Initial Proposals & Feature Requests (Approval Mandatory): Never silently start mutating or building code without explaining the rationale, …
- Very specific: line 33
Never: add #[allow(dead_code)], #[allow(unused)], or #[allow(clippy::...)].
- Distinctive: line 34
If code triggers a warning, fix the underlying cause immediately.
- Very specific: line 36
Never use
mod.rs: Use Rust 2018+ edition file naming: foldername.rs placed alongside the foldername/ directory. - Very specific: line 39
Never: use .unwrap() or .expect() in production or library code.
- Distinctive: line 43
All code must compile cleanly:
- Distinctive: line 55
Keep files, functions, and control flow strictly constrained:
- Very specific: line 93
domain/: Must remain pure; zero network or filesystem dependencies. - Very specific: line 107
Avoid duplicate match arms across multiple files.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
rust-clean-code Skill: Architecture, Scalability & Quality Rules
Enforces strict production standards for Rust projects. Code must be idiomatic, maintainable, modular, and free of compiler or linter warnings.
1. Explicit Approval Protocol (Before Editing Code)
Never edit any code files or apply modifications without first explaining:
- WHY you are making the proposed modification.
- WHAT EFFECT or FIX it will produce.
- Receiving explicit user approval before modifying any code.
Operational Boundaries:
- Initial Proposals & Feature Requests (Approval Mandatory): Never silently start mutating or building code without explaining the rationale, impact, and getting confirmation.
- Autonomous Task Execution & Error Self-Healing (Zero Permission-Seeking): Once approved, you own the implementation end-to-end. If an edit triggers a compiler error (
cargo check), clippy warning (cargo clippy), or broken test, fix it autonomously in a closed loop. NEVER ask the user "I made an error / the test failed, may I fix it?"—resolve it autonomously until green. - Autonomous Release & CI/CD Self-Healing (Zero Permission-Seeking): Once a release is initiated, if GitHub Actions, compilation, or packaging workflows fail due to an error introduced during release/build, fix the issue autonomously without asking permission. Deliver a verified green pipeline.
2. Zero Tolerance Rules (Non-Negotiable)
- No Warning Suppressions:
- Never add
#[allow(dead_code)],#[allow(unused)], or#[allow(clippy::...)]. - If code triggers a warning, fix the underlying cause immediately.
- Never add
- No Old
mod.rs(Modern Module Style):- Never use
mod.rs. Use Rust 2018+ edition file naming:foldername.rsplaced alongside thefoldername/directory. - Example:
src/domain.rsalongsidesrc/domain/user.rs, NOTsrc/domain/mod.rs.
- Never use
- No Production Panics:
- Never use
.unwrap()or.expect()in production or library code. - Propagate typed errors using
Result<T, E>and the?operator. - Reserve
.expect()strictly for unit test assertions with clear context messages.
- Never use
- Zero Compiler Warnings:
- All code must compile cleanly:
cargo clippy --all-targets -- -D warnings cargo fmt --check
- All code must compile cleanly:
- Zero Dead Code:
- Unused imports, unused variables, dead functions, and abandoned struct fields must be deleted immediately.
3. Quantitative Size Limits & Complexity Thresholds
Keep files, functions, and control flow strictly constrained:
| Metric | Soft Limit | Hard Limit | Action if Exceeded |
| File Length | 300 lines | 400 lines | Split into submodules by domain/role |
| Function Length | 40 lines | 60 lines | Extract helper functions or sub-routines |
| Function Parameters | 1–3 parameters | 4 parameters | Group inputs into a dedicated struct / options object |
| Nesting Depth | 2 levels | 3 levels | Guard clauses, early returns, helper decomposition |
| Files per Folder | 3–5 files | 7 files | Subdivide into cohesive domain subfolders |
4. Role-Based Folder Architecture
Organize src/ by architectural role rather than flat file dumps:
src/
├── main.rs / lib.rs # Root declarations & entrypoint only
├── error.rs # Centralized error enum & conversions
├── domain.rs # Declares domain submodule
├── domain/ # Core business entities, models, traits, pure types
│ ├── models.rs
│ └── types.rs
├── infra.rs # Declares infra submodule
├── infra/ # Storage, disk persistence, caching, OS interaction
│ ├── storage.rs
│ └── cache.rs
├── api.rs # Declares api submodule
├── api/ # External HTTP/network clients, REST endpoints
│ ├── client.rs
│ └── payload.rs
├── cli.rs # Declares cli submodule
└── cli/ # CLI arguments, Clap definitions & input validation
└── args.rsModule Boundary Invariants:
domain/: Must remain pure; zero network or filesystem dependencies.infra/: Encapsulates disk I/O, cache persistence, and hardware interaction.api/: Handles remote communication, returning domain models or typed errors.cli/: Parses input flags and delegates immediately to domain/services.
5. Readability & DRY (Don't Repeat Yourself)
- Centralize Shared Logic:
- Reusable string formatting, time parsing, and byte conversions must reside in a dedicated helper module.
- Constants (URLs, timeouts, default limits) must be declared as module-level
consts, never hardcoded inline.
- Trait-Driven Abstractions:
- Abstract I/O and external services behind traits for testability and flexibility.
- Avoid duplicate
matcharms across multiple files; encapsulate dispatch logic on the enum itself.
- Guard Clauses & Early Returns:
- Flatten nested
if / elseblocks using earlyreturn Err(...)orcontinueto stay within the max 3 nesting depth limit.
- Flatten nested
6. Pre-Commit Verification Checklist
# 1. Format code to standard style
cargo fmt
# 2. Verify zero compiler or Clippy warnings
cargo clippy --all-targets -- -D warnings
# 3. Ensure all unit and integration tests pass
cargo test --all-targetsDoes it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

