agentleFS
massimodeluisamassimodeluisa/rust-best-practices-skill/skills/rust-best-practices/SKILL.md

rust-best-practices

Skill1 starsChanged 3 months agoMITView on GitHub

Write and review production Rust using the official API Guidelines, Style Guide, and this engineering standard: allocation contracts, ownership, Result vs panic, debug_assert, Clippy, tests, rustdoc, unsafe, and Cargo CI. Use when writing, reviewing, or refactoring Rust; choosing borrow vs clone; designing crate APIs; handling errors; bounding heap use; configuring clippy or rustfmt; or when the user runs /rust-best-practices. Do not use for other languages. Triggers: rust, rustc, cargo, clippy, rustfmt, ownership, clone, borrow, Result, unwrap, expect, panic, thiserror, anyhow, heapless, no_std, allocation, debug_assert, type-state, Send, Sync, unsafe, FFI, rustdoc, MSRV, rust-best-practices, rust style, rust guidelines

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

25 rules. 0 are common, 9 are distinctive, and 16 are very specific to this project.

  • 0

    Common

    Most of the 23 edited versions we read keep these.

  • 9

    Distinctive

    This author's own choices. Worth a look.

  • 16

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    MUST / MUST NOT: required unless an approved architecture decision documents an exception.

    line 20
  2. Distinctive:

    SHOULD / SHOULD NOT: default.

    line 21
  3. Very specific:

    MUST make invalid states hard to represent: newtypes, enums, Option, Result, type-state where lifecycle matters.

    line 51
  4. Distinctive:

    MUST keep fields private unless direct access is the contract (C-STRUCT-PRIVATE).

    line 52
  5. Very specific:

    MUST follow official as_ / to_ / into_ conversion naming (C-CONV).

    line 53
  6. Distinctive:

    SHOULD return values from general library APIs (C-NO-OUT).

    line 54
  7. Very specific:

    NEVER use a raw u32 for every identifier merely because the representation matches.

    line 55
  8. Distinctive:

    MUST declare a memory profile for each crate and performance-sensitive public operation: strict heapless, allocation-free steady state, or …

    line 59
  9. Distinctive:

    MUST keep runtime work bounded (iterations, recursion, queues, retries, output, concurrency).

    line 60
  10. Distinctive:

    MUST report capacity exhaustion as a typed error.

    line 61
  11. Very specific:

    NEVER treat Cow::into_owned(), format!(), or a spill-capable small-vector as heapless.

    line 62
  12. Very specific:

    SHOULD take &T, &str, &[T], &Path unless ownership transfer is required.

    line 66
  13. Very specific:

    SHOULD pass small Copy values by value.

    line 67
  14. Distinctive:

    NEVER clone to silence the borrow checker.

    line 68
  15. Very specific:

    MUST return Result<T, E> for recoverable failure.

    line 72
  16. Distinctive:

    MUST use checked arithmetic at trust boundaries before indexing or allocating.

    line 73
  17. Very specific:

    MUST validate external input in all builds.

    line 74
  18. Very specific:

    SHOULD use thiserror in libraries, anyhow only at binary boundaries.

    line 75
  19. Very specific:

    MUST #![forbid(unsafe_code)] in crates that do not need unsafe.

    line 79
  20. Very specific:

    MUST document every unsafe block with SAFETY:.

    line 80
  21. Very specific:

    MUST NOT add unsafe Send/Sync impls without a written proof.

    line 81
  22. Very specific:

    SHOULD prefer a single owner or bounded message passing over Arc<Mutex<T>> as an ownership escape hatch.

    line 82
  23. Very specific:

    MUST run cargo fmt --all -- --check and cargo clippy --workspace --all-targets --all-features --locked -- -D warnings in CI (explicit …

    line 86
  24. Very specific:

    SHOULD prefer #[expect(...)] over #[allow(...)], local and justified.

    line 87
  25. Very specific:

    MUST link every committed TODO to an issue: // TODO(#123): ....

    line 88

“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

Apply this standard when writing or reviewing Rust. Engineering guide, not a tutorial.

Authority

  1. Live official docs for language, naming, formatting, and public API shape. Start with the Style Guide and the API Guidelines. Map: references/official.md.
  2. This skill for allocation contracts, bounds, debug_assert!, heapless cores, determinism, and CI. Load the matching reference; do not invent a rule that lives there.

MUST / MUST NOT: required unless an approved architecture decision documents an exception. SHOULD / SHOULD NOT: default; a deviation needs a concrete reason in review. MAY: optional and context-dependent.

Correctness, safety, determinism, and maintainability outrank cleverness. Measure performance. Design allocation and bounds into the API before profiling.

Fetch current official docs for library or toolchain syntax. Do not invent APIs from memory.

How to use

  • /rust-best-practices: apply the standard to the current Rust work.
  • /rust-best-practices <path>: review that crate or file. For each finding: quote the line, name the rule (official C-* id or a heading in this skill), give the fix.

Load only what the task needs, same turn, in parallel:

TaskRead
Naming, rustdoc sections, official checklistofficial.md
Memory profile, heapless, output buffers, hidden allocallocation.md
Borrow vs clone, Copy, into_/to_/as_ownership.md
Result, panic, thiserror/anyhow, checked math, debug_assert!errors.md
Functions, iterators, dispatch, type-state, boolean blindnessdesign.md
Pointers, Send/Sync, unsafe, FFIunsafe.md
Measure, layout, clones, flamegraphperformance.md
rustfmt, Clippy, tests, docs, deps, MSRV, CIquality.md
Review pass, anti-patternsreview.md

Always-on rules

Types and APIs

  • MUST make invalid states hard to represent: newtypes, enums, Option, Result, type-state where lifecycle matters.
  • MUST keep fields private unless direct access is the contract (C-STRUCT-PRIVATE).
  • MUST follow official as_ / to_ / into_ conversion naming (C-CONV).
  • SHOULD return values from general library APIs (C-NO-OUT). MUST use caller-owned buffers when the declared memory profile is heapless or allocation-free (C-CALLER-CONTROL).
  • NEVER use a raw u32 for every identifier merely because the representation matches.

Memory

  • MUST declare a memory profile for each crate and performance-sensitive public operation: strict heapless, allocation-free steady state, or allocation-conscious. Details: allocation.md.
  • MUST keep runtime work bounded (iterations, recursion, queues, retries, output, concurrency).
  • MUST report capacity exhaustion as a typed error. MUST NOT spill to the heap, drop entries, or switch to an unbounded fallback in silence.
  • NEVER treat Cow::into_owned(), format!(), or a spill-capable small-vector as heapless.

Ownership

  • SHOULD take &T, &str, &[T], &Path unless ownership transfer is required.
  • SHOULD pass small Copy values by value. Measure ABI and target when size is in question; do not apply a universal byte cutoff.
  • NEVER clone to silence the borrow checker.

Errors and asserts

  • MUST return Result<T, E> for recoverable failure. MUST NOT unwrap() / expect() on production paths.
  • MUST use checked arithmetic at trust boundaries before indexing or allocating.
  • MUST validate external input in all builds. NEVER use debug_assert! as caller validation or as the only unsafe precondition.
  • SHOULD use thiserror in libraries, anyhow only at binary boundaries.

Unsafe and concurrency

  • MUST #![forbid(unsafe_code)] in crates that do not need unsafe.
  • MUST document every unsafe block with SAFETY:.
  • MUST NOT add unsafe Send/Sync impls without a written proof.
  • SHOULD prefer a single owner or bounded message passing over Arc<Mutex<T>> as an ownership escape hatch.

Quality

  • MUST run cargo fmt --all -- --check and cargo clippy --workspace --all-targets --all-features --locked -- -D warnings in CI (explicit feature matrix if --all-features is invalid).
  • SHOULD prefer #[expect(...)] over #[allow(...)], local and justified.
  • MUST link every committed TODO to an issue: // TODO(#123): ....

Official docs

Cite the live page. Do not restate official rules as if they originated here. Minimum set: Style Guide, API Guidelines checklist, debug_assert!, no_std, alloc, Clippy configuration, Cargo profiles. Full list: official.md.

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.