rust-skills
Skill13 starsChanged 3 months agoApache-2.0View on GitHub
Comprehensive Rust coding guidelines with 265 rules across 26 categories. Use when writing, reviewing, or refactoring Rust code. Covers ownership, error handling, async patterns, concurrency, unsafe code, API design, memory optimization, performance, numeric safety, conversions, serde, pattern matching, macros, closures, observability, testing, and common anti-patterns. Invoke with /rust-skills.
4 other projects use a version of this, 4 of them edited.
Adopted by
Most recently taken up by
- idexal/idexal-skillsedited, first seen Aug 26, 2026
- leonardomso/rust-skillsedited, first seen Jun 14, 2026
- launchapp-dev/animus-cliedited, first seen Mar 15, 2026
- chasebuild/fuelcheck-cliedited, first seen Feb 16, 2026
Other versions4 projects use a version of this.
Word for word · 0
None found.
Edited · 4
- leonardomso/rust-skills★ 56362% same
- launchapp-dev/animus-cli★ 3826% same
- chasebuild/fuelcheck-cli★ 1526% same
- idexal/idexal-skills★ 1362% same
Wrote their own version · 0
None found.
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 repository31 other files it gives its agents.
- AGENTS.mdAGENTS.md
- paper-writingSkill
- research-surveySkill
- brainstormingSkill
- ci-cdSkill
- cli-sarifSkill
- dispatching-parallel-agentsSkill
- executing-plansSkill
- finishing-a-development-branchSkill
- neutralize-sd11Skill
- project-contextSkill
- receiving-code-reviewSkill
- release-publishSkill
- requesting-code-reviewSkill
- review-botsSkill
- rust-best-practicesSkill
- rust-idiomsSkill
- rust-invariantsSkill
- rust-perfSkill
- rust-testingSkill
- rust-workspaceSkill
- subagent-driven-developmentSkill
- systematic-debuggingSkill
- test-driven-developmentSkill
- unsafe-sandboxSkill
- using-git-worktreesSkill
- using-superpowersSkill
- verification-before-completionSkill
- writing-plansSkill
- writing-skillsSkill
- yara-rulesSkill
The file
Files
Rust Best Practices
Comprehensive guide for writing high-quality, idiomatic, and highly optimized Rust code. Contains 265 rules across 26 categories, prioritized by impact to guide LLMs in code generation and refactoring. Current for Rust 1.96 (2024 edition).
When to Apply
Reference these guidelines when:
- Writing new Rust functions, structs, or modules
- Implementing error handling or async code
- Writing concurrent, parallel, or
unsafecode - Designing public APIs for libraries
- Reviewing code for ownership/borrowing issues
- Optimizing memory usage or reducing allocations
- Tuning performance for hot paths
- Refactoring existing Rust code
Rule Categories by Priority
| Priority | Category | Impact | Prefix | Rules |
| 1 | Ownership & Borrowing | CRITICAL | own- | 12 |
| 2 | Error Handling | CRITICAL | err- | 12 |
| 3 | Memory Optimization | CRITICAL | mem- | 17 |
| 4 | Unsafe Code | CRITICAL | unsafe- | 7 |
| 5 | API Design | HIGH | api- | 17 |
| 6 | Async/Await | HIGH | async- | 18 |
| 7 | Concurrency | HIGH | conc- | 4 |
| 8 | Compiler Optimization | HIGH | opt- | 12 |
| 9 | Numeric & Arithmetic Safety | HIGH | num- | 5 |
| 10 | Type Safety | MEDIUM | type- | 13 |
| 11 | Trait & Generics Design | MEDIUM | trait- | 6 |
| 12 | Conversions | MEDIUM | conv- | 3 |
| 13 | Const & Compile-Time | MEDIUM | const- | 4 |
| 14 | Serde | MEDIUM | serde- | 8 |
| 15 | Pattern Matching | MEDIUM | pat- | 5 |
| 16 | Macros | MEDIUM | macro- | 8 |
| 17 | Closures | MEDIUM | closure- | 5 |
| 18 | Collections | MEDIUM | coll- | 4 |
| 19 | Naming Conventions | MEDIUM | name- | 16 |
| 20 | Testing | MEDIUM | test- | 15 |
| 21 | Documentation | MEDIUM | doc- | 12 |
| 22 | Observability | MEDIUM | obs- | 7 |
| 23 | Performance Patterns | MEDIUM | perf- | 13 |
| 24 | Project Structure | LOW | proj- | 14 |
| 25 | Clippy & Linting | LOW | lint- | 13 |
| 26 | Anti-patterns | REFERENCE | anti- | 15 |
Quick Reference
1. Ownership & Borrowing (CRITICAL)
own-borrow-over-clone- Prefer&Tborrowing over.clone()own-slice-over-vec- Accept&[T]not&Vec<T>,&strnot&Stringown-cow-conditional- UseCow<'a, T>for conditional ownershipown-arc-shared- UseArc<T>for thread-safe shared ownershipown-rc-single-thread- UseRc<T>for shared ownership in single-threaded contextsown-refcell-interior- UseRefCell<T>for interior mutability in single-threaded codeown-mutex-interior- UseMutex<T>for interior mutability across threadsown-rwlock-readers- UseRwLock<T>when reads significantly outnumber writesown-copy-small- ImplementCopyfor small, simple typesown-clone-explicit- Use explicitClonefor types where copying has meaningful costown-move-large- Move large types instead of copying; useBoxif moves are expensiveown-lifetime-elision- Rely on lifetime elision rules; add explicit lifetimes only when required
2. Error Handling (CRITICAL)
err-thiserror-lib- Usethiserrorfor library error typeserr-anyhow-app- Useanyhowfor application error handlingerr-result-over-panic- ReturnResult<T, E>instead of panicking for recoverable errorserr-context-chain- Add context with.context()or.with_context()err-no-unwrap-prod- Avoidunwrap()in production code; use?,expect(), or handle errorserr-expect-bugs-only- Useexpect()only for invariants that indicate bugs, not user errorserr-question-mark- Use?operator for clean propagationerr-from-impl- ImplementFrom<E>for error conversions to enable?operatorerr-source-chain- Preserve error chains with#[source]orsource()methoderr-lowercase-msg- Start error messages lowercase, no trailing punctuationerr-doc-errors- Document error conditions with# Errorssection in doc commentserr-custom-type- Define custom error types for domain-specific failures
3. Memory Optimization (CRITICAL)
mem-with-capacity- Usewith_capacity()when size is knownmem-smallvec- UseSmallVecfor usually-small collectionsmem-arrayvec- UseArrayVec<T, N>for fixed-capacity collections that never heap-allocatemem-box-large-variant- Box large enum variants to reduce overall enum sizemem-boxed-slice- UseBox<[T]>instead ofVec<T>for fixed-size heap datamem-thinvec- UseThinVec<T>for nullable collections with minimal overheadmem-clone-from- Useclone_from()to reuse allocations when repeatedly cloningmem-reuse-collections- Clear and reuse collections instead of creating new ones in loopsmem-avoid-format- Avoidformat!()when string literals workmem-write-over-format- Usewrite!()into existing buffers instead offormat!()allocationsmem-arena-allocator- Use arena allocators for batch allocationsmem-zero-copy- Use zero-copy patterns with slices andBytesmem-compact-string- Use compact string types for memory-constrained string storagemem-smaller-integers- Use appropriately-sized integers to reduce memory footprintmem-assert-type-size- Use static assertions to guard against accidental type size growthmem-take-replace- Usemem::take/mem::replaceto move a value out of a&mutwithout cloningmem-drop-order- Know and control drop order: struct fields drop top-to-bottom, locals in reverse
4. Unsafe Code (CRITICAL)
unsafe-safety-comment- Write a// SAFETY:comment above everyunsafeblock and a# Safetysection in everyunsafe fn.unsafe-minimize-scope- Keepunsafeblocks as small as possible — mark only the operation that requires unsafety, not the surrounding safe code.unsafe-miri-ci- Runcargo miri testin CI for every crate that containsunsafecode.unsafe-maybeuninit- UseMaybeUninit<T>for uninitialized memory; never usemem::uninitialized()ormem::zeroed()for types with validity invariants.unsafe-extern-block- In Rust 2024, wrapexternblocks inunsafe extern { }and annotate each item assafeorunsafe.unsafe-send-sync-manual- Document the invariants when manually implementingSendorSync; prefer letting the compiler derive them automatically.unsafe-no-mangle-unsafe- In Rust 2024, write#[unsafe(no_mangle)],#[unsafe(export_name = "...")], and#[unsafe(link_section = "...")]— not the bare attribute forms.
5. API Design (HIGH)
api-builder-pattern- Use Builder pattern for complex constructionapi-builder-must-use- Mark builder methods with#[must_use]to prevent silent dropsapi-newtype-safety- Use newtypes to prevent mixing semantically different valuesapi-typestate- Use typestate pattern to encode state machine invariants in the type systemapi-sealed-trait- Use sealed traits to prevent external implementations while allowing useapi-extension-trait- Use extension traits to add methods to external typesapi-parse-dont-validate- Parse into validated types at boundariesapi-impl-into- Acceptimpl Into<T>for flexible APIs, implementFrom<T>for conversionsapi-impl-asref- UseAsRef<T>when you only need to borrow the inner dataapi-must-use- Mark types and functions with#[must_use]when ignoring results is likely a bugapi-non-exhaustive- Use#[non_exhaustive]on public enums and structs for forward compatibilityapi-from-not-into- ImplementFrom<T>, notInto<U>- From gives you Into for freeapi-default-impl- ImplementDefaultfor types with sensible default valuesapi-common-traits- Implement standard traits (Debug, Clone, PartialEq, etc.) for public typesapi-serde-optional- Make serde a feature flag, not a hard dependency for library cratesapi-impl-fromiterator- ImplementFromIteratorandExtendfor collection types, andIntoIteratorfor all three reference formsapi-operator-overload- Overload operators only when the semantics are natural and unsurprising
6. Async/Await (HIGH)
async-tokio-runtime- Configure Tokio runtime appropriately for your workloadasync-no-lock-await- Never holdMutex/RwLockacross.awaitasync-spawn-blocking- Usespawn_blockingfor CPU-intensive workasync-tokio-fs- Usetokio::fsinstead ofstd::fsin async codeasync-cancellation-token- UseCancellationTokenfor graceful shutdown and task cancellationasync-join-parallel- Usejoin!ortry_join!for concurrent independent futuresasync-try-join- Usetry_join!for concurrent fallible operations with early return on errorasync-select-racing- Useselect!to race futures and handle the first to completeasync-bounded-channel- Use bounded channels to apply backpressure and prevent unbounded memory growthasync-mpsc-queue- Usempscchannels for async message queues between tasksasync-broadcast-pubsub- Usebroadcastchannel for pub/sub where all subscribers receive all messagesasync-watch-latest- Usewatchchannel for sharing the latest value with multiple observersasync-oneshot-response- Useoneshotchannel for request-response patternsasync-joinset-structured- UseJoinSetfor managing dynamic collections of spawn
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.

