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
- linx-systems/clamuitheir own version, first seen Nov 9, 2026
- Cosmian/kmstheir own version, first seen Nov 9, 2026
- dirien/yet-another-agent-harnesstheir own version, first seen Nov 8, 2026
- crbnos/carbontheir own version, first seen Nov 7, 2026
- iyazerski/dev-flows-plugintheir own version, first seen Nov 1, 2026
- MaraniMatias/Mustertheir own version, first seen Nov 1, 2026
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.
klauswgSkillrust-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
weedmoSkillrust-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
xfstudioSkillinngest
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
huialiSkillrust-testing
Also in 7 projects that use this
CloudflareSkillrust-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-devSkilltauri-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
Other versions46 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 46
- farm-fe/farm★ 5.6ksame name
- crbnos/carbon★ 2.8ksame name
- morganlinton/BeautifulRust★ 1.8ksame name
- pedronauck/skills★ 649same name
- Cosmian/kms★ 372same name
- linx-systems/clamui★ 372same name
- openbezal/rhema★ 354same name
- apollographql/apollo-mcp-server★ 318same name
- apollographql/skills★ 123same name
- Blushyes/reef★ 84same name
36 more not listed
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository57 other files it gives its agents.
- ai-app-integrationSkill
- anti-llm-frontend-designSkill
- aspnet-core-web-developmentSkill
- async-python-patternsSkill
- browser-game-foundationsSkill
- browser-local-qaSkill
- build-mcp-server-sdk-v2Skill
- canva-design-opsSkill
- check-completionSkill
- cli-tool-creatorSkill
- cloudflare-agents-mcpSkill
- cloudflare-durable-objectsSkill
- cloudflare-workers-platformSkill
- deployment-preview-workflowsSkill
- docx-document-artifactsSkill
- durable-workflow-orchestrationSkill
- dynamic-og-imagesSkill
- eval-auditSkill
- evaluate-ragSkill
- figma-design-to-code-rulesSkill
- fine-tuningSkill
- frontend-product-builderSkill
- game-asset-pipeline-expansionSkill
- game-ui-playtestSkill
- generate-synthetic-dataSkill
- github-pr-ci-opsSkill
- gmail-inbox-opsSkill
- golden-datasetSkill
- huggingface-llm-trainerSkill
- javascript-monorepo-buildsSkill
- linear-issue-managementSkill
- media-generation-transcriptionSkill
- millrace-rs-contract-paritySkill
- minecraft-mod-qa-automationSkill
- notion-workspace-flowsSkill
- openai-docsSkill
- optimize-agentic-cliSkill
- pdf-artifact-workflowSkill
- phaser-2d-game-developmentSkill
- postgres-query-performanceSkill
- product-ui-polish-reviewSkill
- pydantic-v2-patternsSkill
- python-repo-refactoring-hygieneSkill
- rag-corpus-hygieneSkill
- react-next-performance-reviewSkill
- shadcn-ui-compositionSkill
- skill-evaluation-harnessSkill
- tauri-desktopSkill
- tauri-mcp-cliSkill
- tauri-ptySkill
- tile-pixel-art-transitionsSkill
- train-sentence-transformersSkill
- typer-cli-patternsSkill
- using-dbt-for-analytics-engineeringSkill
- validate-evaluatorSkill
- visual-asset-pipelineSkill
- watchdog-file-watcher-patternsSkill
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
- Very specific: line 39
Prefer borrowed parameters: &str, &[T], and &T unless ownership is required.
- Distinctive: line 41
Use typed errors in libraries and contextual aggregate errors at binary/application edges.
- Very specific: line 42
Run cargo fmt, cargo clippy, and targeted tests before claiming completion.
- Distinctive: line 44
Document public APIs and leave comments for intent, invariants, or safety, not line-by-line narration.
- Distinctive: line 47
Do not clone to satisfy the borrow checker until you know ownership is required.
- Distinctive: line 48
Prefer iterators and slices without adding intermediate collections unless the collection is needed.
- Very specific: line 49
Keep unsafe rare, isolated, and documented with a SAFETY: invariant.
- Very specific: line 50
Use thiserror or equivalent typed errors for library boundaries.
- Distinctive: line 51
Avoid wildcard matches on domain enums when future variants should force a compile failure.
- Distinctive: line 52
Prefer generics for hot homogeneous paths and trait objects for heterogeneous collections or stable ABI-like boundaries.
- Very specific: line 53
Use #[expect(...)] with a justification when suppressing lints, not broad unexplained allow.
- Distinctive: line 54
Keep public docs, examples, and doctests aligned with the actual API.
- Distinctive: line 70
Read the surrounding Rust style, crate boundaries, feature flags, and existing error types.
- Distinctive: line 73
Keep data transformations allocation-aware.
- Distinctive: line 74
Use type-state, sealed traits, or stronger enums only when they remove real invalid states.
- Distinctive: line 75
Add focused unit, integration, or doctests around behavior that can regress.
- Distinctive: line 76
Run formatting, linting, and tests with the repo's normal commands.
- Very specific: line 91
Run cargo fmt --check or the repo's formatter command.
- Very specific: line 92
Run cargo clippy --all-targets --all-features -- -D warnings when compatible with the repo.
- Very specific: line 93
Run targeted cargo test commands for changed crates or modules.
“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.
Files
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
- Prefer borrowed parameters:
&str,&[T], and&Tunless ownership is required. - Return
Resultfor fallible runtime paths; avoidpanic!,unwrap, andexpectoutside tests or startup invariants. - Use typed errors in libraries and contextual aggregate errors at binary/application edges.
- Run
cargo fmt,cargo clippy, and targeted tests before claiming completion. - Benchmark performance-sensitive changes in release mode before optimizing.
- 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
unsaferare, isolated, and documented with aSAFETY:invariant. - Use
thiserroror equivalent typed errors for library boundaries; useanyhowor 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 unexplainedallow. - 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
- Read the surrounding Rust style, crate boundaries, feature flags, and existing error types.
- Choose borrowing, ownership, or
Cowbased on call-site needs. - Model fallible behavior with
Resultand domain errors before adding broad string errors. - Keep data transformations allocation-aware; remove redundant clones and needless collections.
- Use type-state, sealed traits, or stronger enums only when they remove real invalid states.
- Add focused unit, integration, or doctests around behavior that can regress.
- Run formatting, linting, and tests with the repo's normal commands.
Pitfalls And Gotchas
- Cloning inside loops because borrow errors were not understood.
- Returning
Stringerrors from library code that callers need to match. - Using
unwrapin 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 --checkor the repo's formatter command. - Run
cargo clippy --all-targets --all-features -- -D warningswhen compatible with the repo. - Run targeted
cargo testcommands 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.
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
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.

