agentleFS
BigtoCBigtoC/my-skills/skills/rust-best-practices/SKILL.md

rust-best-practices

Skill1 starsChanged 3 months agoMITView on GitHub

Rust coding conventions and review guidance. Auto-invoke whenever working with .rs files or Rust code -- implementing features, reviewing changes, refactoring modules, designing public APIs, improving tests, or optimizing performance.

24 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use inngest, go-best-practices and 10 more.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • xfstudioSkill

    inngest

    Inngest expert for serverless-first background jobs, event-driven workflows, and durable execution without managing queues or workers. Use when: inngest, serverless background job, event-driven workflow, step function, durable execution.

    Also in 3 projects that use this

  • mduongvandinhSkill

    go-best-practices

    Also in 3 projects that use this

  • rohitg00Skill

    typescript-advanced

    Advanced TypeScript patterns including generics, conditional types, mapped types, template literals, and type guards

    Also in 3 projects that use this

  • xfstudioSkill

    rust-async-patterns

    Master Rust async programming with Tokio, async traits, error handling, and concurrent patterns. Use when building async Rust applications, implementing concurrent systems, or debugging async code.

    Also in 3 projects that use this

  • dbDev-codeSkill

    tauri-v2

    Tauri v2+ cross-platform app development with Rust backend. Use when configuring tauri.conf.json, implementing Rust commands (#[tauri::command]), setting up IPC patterns (invoke, emit, channels), configuring permissions/capabilities, troubleshooting build issues, or deploying desktop/mobile apps. Triggers on Tauri, src-tauri, invoke, emit, capabilities.json.

    Also in 3 projects that use this

  • VercelSkill

    vercel-react-best-practices

    React and Next.js performance optimization guidelines from Vercel Engineering. This skill should be used when writing, reviewing, or refactoring React/Next.js code to ensure optimal performance patterns. Triggers on tasks involving React components, Next.js pages, data fetching, bundle optimization, or performance improvements.

    Also in 6 projects that use this

The file

Show its rules and text

We split this skill into the rules it gives an agent

21 rules. 0 are common, 16 are distinctive, and 5 are very specific to this project.

  • 0

    Common

    Most of the 23 edited versions we read keep these.

  • 16

    Distinctive

    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:

    Use this skill when a task involves Rust code: implementing features, reviewing changes, refactoring modules, designing public APIs, …

    line 18
  2. Distinctive:

    Keep solutions idiomatic, safe, and maintainable.

    line 56
  3. Very specific:

    Prefer borrowing over cloning, Result over panics, and focused modules over large mixed-responsibility files.

    line 64
  4. Very specific:

    When refactoring, preserve the public surface and use mod.rs re-exports or other facade patterns to hide internal changes.

    line 66
  5. Distinctive:

    When optimizing, profile first and improve algorithms before micro-tuning allocations or concurrency.

    line 68
  6. Distinctive:

    Document public APIs, cover edge cases with tests, and keep standard Rust tooling green if the project uses it.

    line 70
  7. Distinctive:

    Write idiomatic Rust that compiles cleanly and avoids warnings.

    line 75
  8. Very specific:

    Prefer &str over String for parameters when ownership is not required.

    line 76
  9. Very specific:

    Avoid unwrap(), expect(), and panics in library code.

    line 77
  10. Distinctive:

    Use meaningful error types and add context to failures.

    line 78
  11. Distinctive:

    Avoid duplicated logic, unnecessary wrappers, and deep nesting.

    line 79
  12. Distinctive:

    Keep modules cohesive and split large files by responsibility.

    line 80
  13. Distinctive:

    Treat performance advice as opt-in for measured bottlenecks, not default complexity.

    line 81
  14. Distinctive:

    When reviewing Rust code, prioritize:

    line 86
  15. Distinctive:

    Test coverage and rustdoc quality

    line 91
  16. Very specific:

    Keep main.rs and lib.rs thin.

    line 96
  17. Distinctive:

    Prefer package-style modules for larger components.

    line 97
  18. Distinctive:

    Use private helper modules and expose only an intentional public surface.

    line 98
  19. Distinctive:

    Remove pass-through wrapper functions that add no value.

    line 99
  20. Distinctive:

    Prefer iterator pipelines, pre-allocation, streaming, and lazy evaluation before more invasive rewrites.

    line 104
  21. Distinctive:

    Consider memory layout and concurrency changes only when the workload justifies them.

    line 106

“Common” is measured: kept by at least 6 in 10 of the 23 edited versions of this file we could read. “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 Best Practices

Auto-invoke this skill whenever a task touches a .rs file or any Rust code. This applies to all agent implementations.

Use this skill when a task involves Rust code: implementing features, reviewing changes, refactoring modules, designing public APIs, improving tests, or optimizing performance.

Auto-Trigger Setup

All agents (description-based)

Agents that load skill descriptions at startup will auto-invoke this skill whenever .rs files or Rust keywords appear in the task context. No extra configuration is needed if your agent follows the Agent Skills specification.

Claude Code (hook-based enforcement)

For guaranteed invocation regardless of context, add this hook to ~/.claude/settings.json:

{
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "Write|Edit",
        "hooks": [
          {
            "type": "command",
            "command": "jq -r '.tool_input.file_path // \"\"' | { read -r f; if printf '%s' \"$f\" | grep -qE '\\.rs$'; then printf '{\"hookSpecificOutput\":{\"hookEventName\":\"PreToolUse\",\"additionalContext\":\"Rust (.rs) file detected. Invoke the rust-best-practices skill now if you have not already done so this session.\"}}'; fi; } 2>/dev/null || true",
            "timeout": 10
          }
        ]
      }
    ]
  }
}

Merge into any existing hooks.PreToolUse array rather than replacing it.

Keep solutions idiomatic, safe, and maintainable. Favor strong typing, explicit error handling, public API stability, and borrowing-first designs.

Core Workflow

  1. Identify the task type: new implementation, review, refactor, API design, debugging, or optimization.
  2. Preserve correctness and readability before chasing cleverness.
  3. Prefer borrowing over cloning, Result over panics, and focused modules over large mixed-responsibility files.
  4. When refactoring, preserve the public surface and use mod.rs re-exports or other facade patterns to hide internal changes.
  5. When optimizing, profile first and improve algorithms before micro-tuning allocations or concurrency.
  6. Document public APIs, cover edge cases with tests, and keep standard Rust tooling green if the project uses it.

Default Guidance

  • Write idiomatic Rust that compiles cleanly and avoids warnings.
  • Prefer &str over String for parameters when ownership is not required.
  • Avoid unwrap(), expect(), and panics in library code.
  • Use meaningful error types and add context to failures.
  • Avoid duplicated logic, unnecessary wrappers, and deep nesting.
  • Keep modules cohesive and split large files by responsibility.
  • Treat performance advice as opt-in for measured bottlenecks, not default complexity.

Review Priorities

When reviewing Rust code, prioritize:

  1. Safety and correctness
  2. Error handling and API clarity
  3. Ownership, borrowing, and allocation behavior
  4. Test coverage and rustdoc quality
  5. Performance issues backed by real workload needs

Refactoring Guidance

  • Keep main.rs and lib.rs thin.
  • Prefer package-style modules for larger components.
  • Use private helper modules and expose only an intentional public surface.
  • Remove pass-through wrapper functions that add no value.

Performance Guidance

  • Optimize only after profiling identifies a real bottleneck.
  • Prefer iterator pipelines, pre-allocation, streaming, and lazy evaluation before more invasive rewrites.
  • Consider memory layout and concurrency changes only when the workload justifies them.

Detailed Reference

See references/REFERENCE.md for the full Rust guidance, including:

  • ownership and lifetime rules
  • patterns to follow and avoid
  • API design guidelines
  • testing and documentation expectations
  • project organization rules
  • performance techniques and optimization priorities
  • a publish/review checklist

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.