agentleFS
PraveensenpaiPraveensenpai/karakuri/skills/build-tooling/rust-clean-code/SKILL.md

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().

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
  1. Distinctive:

    Initial Proposals & Feature Requests (Approval Mandatory): Never silently start mutating or building code without explaining the rationale, …

    line 24
  2. Very specific:

    Never: add #[allow(dead_code)], #[allow(unused)], or #[allow(clippy::...)].

    line 33
  3. Distinctive:

    If code triggers a warning, fix the underlying cause immediately.

    line 34
  4. Very specific:

    Never use mod.rs: Use Rust 2018+ edition file naming: foldername.rs placed alongside the foldername/ directory.

    line 36
  5. Very specific:

    Never: use .unwrap() or .expect() in production or library code.

    line 39
  6. Distinctive:

    All code must compile cleanly:

    line 43
  7. Distinctive:

    Keep files, functions, and control flow strictly constrained:

    line 55
  8. Very specific:

    domain/: Must remain pure; zero network or filesystem dependencies.

    line 93
  9. Very specific:

    Avoid duplicate match arms across multiple files.

    line 107

≈ “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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

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:

  1. WHY you are making the proposed modification.
  2. WHAT EFFECT or FIX it will produce.
  3. 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)

  1. No Warning Suppressions:
    • Never add #[allow(dead_code)], #[allow(unused)], or #[allow(clippy::...)].
    • If code triggers a warning, fix the underlying cause immediately.
  2. No Old mod.rs (Modern Module Style):
    • Never use mod.rs. Use Rust 2018+ edition file naming: foldername.rs placed alongside the foldername/ directory.
    • Example: src/domain.rs alongside src/domain/user.rs, NOT src/domain/mod.rs.
  3. 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.
  4. Zero Compiler Warnings:
    • All code must compile cleanly:
      cargo clippy --all-targets -- -D warnings
      cargo fmt --check
  5. 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:

MetricSoft LimitHard LimitAction if Exceeded
File Length300 lines400 linesSplit into submodules by domain/role
Function Length40 lines60 linesExtract helper functions or sub-routines
Function Parameters1–3 parameters4 parametersGroup inputs into a dedicated struct / options object
Nesting Depth2 levels3 levelsGuard clauses, early returns, helper decomposition
Files per Folder3–5 files7 filesSubdivide 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.rs

Module 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)

  1. 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.
  2. Trait-Driven Abstractions:
    • Abstract I/O and external services behind traits for testability and flexibility.
    • Avoid duplicate match arms across multiple files; encapsulate dispatch logic on the enum itself.
  3. Guard Clauses & Early Returns:
    • Flatten nested if / else blocks using early return Err(...) or continue to stay within the max 3 nesting depth limit.

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-targets

Download now (ZIP)

Does 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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.