agentleFS
tim-osterhustim-osterhus/millrace-skills/skills/rust-best-practices/SKILL.md

rust-best-practices

Skill0 starsChanged 7 months agoApache-2.0View on GitHub

Implementation guardrail for idiomatic Rust ownership, error handling, linting, performance discipline, testing, documentation, and public API review.

46 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use rust-async-patterns, rust-port 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.
  • klauswgSkill

    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 9 projects that use this

  • weedmoSkill

    rust-port

    Port an existing codebase or hot path to Rust from any language (Python, C, C++, Go, JS/TS, Java/Kotlin, C#) with an oracle-first workflow: profile to pick targets, freeze equivalence tests before porting, design the FFI boundary, then gate on differential tests and 1-thread vs N-thread release benchmarks. Use when the user asks to rewrite, port, migrate, or speed up code in Rust (PyO3/maturin, napi-rs, jni-rs, cxx, c2rust), or to review such a port.

    Also in 4 projects that use this

  • 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

  • huialiSkill

    rust-testing

    Also in 7 projects that use this

  • CloudflareSkill

    rust-review

    Rust code review for workerd. Covers CXX FFI safety, unsafe code patterns, JSG resource conventions, error handling, and a review checklist adapted from the C++ review skills. Load this skill when reviewing Rust code in src/rust/.

    Also in 4 projects that use this

  • gihwan-devSkill

    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 6 projects that use this

The file

Show its rules and text

We split this skill into the rules it gives an agent

20 rules. 0 are common, 12 are distinctive, and 8 are very specific to this project.

  • 0

    Common

    Most of the 45 edited versions we read keep these.

  • 12

    Distinctive

    This author's own choices. Worth a look.

  • 8

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Prefer borrowed parameters: &str, &[T], and &T unless ownership is required.

    line 39
  2. Distinctive:

    Use typed errors in libraries and contextual aggregate errors at binary/application edges.

    line 41
  3. Very specific:

    Run cargo fmt, cargo clippy, and targeted tests before claiming completion.

    line 42
  4. Distinctive:

    Document public APIs and leave comments for intent, invariants, or safety, not line-by-line narration.

    line 44
  5. Distinctive:

    Do not clone to satisfy the borrow checker until you know ownership is required.

    line 47
  6. Distinctive:

    Prefer iterators and slices without adding intermediate collections unless the collection is needed.

    line 48
  7. Very specific:

    Keep unsafe rare, isolated, and documented with a SAFETY: invariant.

    line 49
  8. Very specific:

    Use thiserror or equivalent typed errors for library boundaries.

    line 50
  9. Distinctive:

    Avoid wildcard matches on domain enums when future variants should force a compile failure.

    line 51
  10. Distinctive:

    Prefer generics for hot homogeneous paths and trait objects for heterogeneous collections or stable ABI-like boundaries.

    line 52
  11. Very specific:

    Use #[expect(...)] with a justification when suppressing lints, not broad unexplained allow.

    line 53
  12. Distinctive:

    Keep public docs, examples, and doctests aligned with the actual API.

    line 54
  13. Distinctive:

    Read the surrounding Rust style, crate boundaries, feature flags, and existing error types.

    line 70
  14. Distinctive:

    Keep data transformations allocation-aware.

    line 73
  15. Distinctive:

    Use type-state, sealed traits, or stronger enums only when they remove real invalid states.

    line 74
  16. Distinctive:

    Add focused unit, integration, or doctests around behavior that can regress.

    line 75
  17. Distinctive:

    Run formatting, linting, and tests with the repo's normal commands.

    line 76
  18. Very specific:

    Run cargo fmt --check or the repo's formatter command.

    line 91
  19. Very specific:

    Run cargo clippy --all-targets --all-features -- -D warnings when compatible with the repo.

    line 92
  20. Very specific:

    Run targeted cargo test commands for changed crates or modules.

    line 93

“Common” is measured: kept by at least 6 in 10 of the 45 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

Purpose

Help agents write and review idiomatic Rust that respects ownership, explicit errors, lint discipline, performance evidence, tests, and documentation. This skill is for ordinary Rust quality; use narrower domain skills when Rust is only one part of a larger platform contract.

Use When

  • writing, refactoring, or reviewing Rust code
  • deciding between borrowing, cloning, ownership transfer, generics, trait objects, or type-state patterns
  • shaping library and binary error boundaries
  • adding tests, docs, lint rules, or performance-sensitive changes

Do Not Use When

  • a repo-specific Rust contract skill already owns the behavior
  • the task is only cargo invocation with no code or design judgment
  • the user explicitly wants a quick syntax answer

Quick Start

  1. Prefer borrowed parameters: &str, &[T], and &T unless ownership is required.
  2. Return Result for fallible runtime paths; avoid panic!, unwrap, and expect outside tests or startup invariants.
  3. Use typed errors in libraries and contextual aggregate errors at binary/application edges.
  4. Run cargo fmt, cargo clippy, and targeted tests before claiming completion.
  5. Benchmark performance-sensitive changes in release mode before optimizing.
  6. Document public APIs and leave comments for intent, invariants, or safety, not line-by-line narration.

Operating Constraints

  • Do not clone to satisfy the borrow checker until you know ownership is required.
  • Prefer iterators and slices without adding intermediate collections unless the collection is needed.
  • Keep unsafe rare, isolated, and documented with a SAFETY: invariant.
  • Use thiserror or equivalent typed errors for library boundaries; use anyhow or similar context at application edges when appropriate.
  • Avoid wildcard matches on domain enums when future variants should force a compile failure.
  • Prefer generics for hot homogeneous paths and trait objects for heterogeneous collections or stable ABI-like boundaries.
  • Use #[expect(...)] with a justification when suppressing lints, not broad unexplained allow.
  • Keep public docs, examples, and doctests aligned with the actual API.

Inputs This Skill Expects

  • The Rust crate, module, or API being changed.
  • Whether the code is library, binary, test support, async runtime, FFI, or performance-sensitive code.
  • Existing lint, formatting, and test commands.
  • Any constraints around MSRV, feature flags, no-std, async runtime, or public API compatibility.

Output Contract

  • Name the ownership and error-handling choices that matter for the change.
  • Identify any intentional clones, allocations, dynamic dispatch, unsafe blocks, or lint suppressions.
  • Include the validation commands run or the precise reason they could not run.
  • For performance work, include benchmark or profiling evidence rather than intuition.
  • For public API changes, state docs and compatibility impact.

Procedure

  1. Read the surrounding Rust style, crate boundaries, feature flags, and existing error types.
  2. Choose borrowing, ownership, or Cow based on call-site needs.
  3. Model fallible behavior with Result and domain errors before adding broad string errors.
  4. Keep data transformations allocation-aware; remove redundant clones and needless collections.
  5. Use type-state, sealed traits, or stronger enums only when they remove real invalid states.
  6. Add focused unit, integration, or doctests around behavior that can regress.
  7. Run formatting, linting, and tests with the repo's normal commands.

Pitfalls And Gotchas

  • Cloning inside loops because borrow errors were not understood.
  • Returning String errors from library code that callers need to match.
  • Using unwrap in runtime code because a failure seems impossible.
  • Boxing or dynamic dispatch before measuring whether static dispatch is too limiting.
  • Adding type-state complexity for a simple runtime check.
  • Treating debug-mode timing as performance evidence.
  • Writing comments that restate syntax instead of documenting the reason or invariant.

Progressive Disclosure

Start with the local module and crate conventions. Expand into lint configuration, benchmarks, public API documentation, or deeper ownership redesign only when the change touches those boundaries. Keep advice scoped to the code under review rather than turning every Rust task into a full style audit.

Verification Pattern

  • Run cargo fmt --check or the repo's formatter command.
  • Run cargo clippy --all-targets --all-features -- -D warnings when compatible with the repo.
  • Run targeted cargo test commands for changed crates or modules.
  • For feature-gated crates, test the relevant feature combinations.
  • For performance claims, run release-mode benchmarks or profiling and report the evidence.

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.