rust-skills▌
leonardomso/rust-skills · updated Apr 8, 2026
179 Rust coding rules across 14 categories, prioritized by impact for writing idiomatic, optimized, and maintainable code.
- ›Covers critical foundations: ownership and borrowing, error handling, memory optimization, and API design with detailed rules and examples
- ›Includes high-priority async/await patterns, compiler optimization techniques, and performance tuning strategies for production systems
- ›Provides medium-priority guidance on naming conventions, type safety, testing, documentati
Rust Best Practices
Comprehensive guide for writing high-quality, idiomatic, and highly optimized Rust code. Contains 179 rules across 14 categories, prioritized by impact to guide LLMs in code generation and refactoring.
When to Apply
Reference these guidelines when:
- Writing new Rust functions, structs, or modules
- Implementing error handling or async code
- 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- |
15 |
| 4 | API Design | HIGH | api- |
15 |
| 5 | Async/Await | HIGH | async- |
15 |
| 6 | Compiler Optimization | HIGH | opt- |
12 |
| 7 | Naming Conventions | MEDIUM | name- |
16 |
| 8 | Type Safety | MEDIUM | type- |
10 |
| 9 | Testing | MEDIUM | test- |
13 |
| 10 | Documentation | MEDIUM | doc- |
11 |
| 11 | Performance Patterns | MEDIUM | perf- |
11 |
| 12 | Project Structure | LOW | proj- |
11 |
| 13 | Clippy & Linting | LOW | lint- |
11 |
| 14 | 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 single-threaded sharingown-refcell-interior- UseRefCell<T>for interior mutability (single-thread)own-mutex-interior- UseMutex<T>for interior mutability (multi-thread)own-rwlock-readers- UseRwLock<T>when reads dominate writesown-copy-small- DeriveCopyfor small, trivial typesown-clone-explicit- MakeCloneexplicit, avoid implicit copiesown-move-large- Move large data instead of cloningown-lifetime-elision- Rely on lifetime elision when possible
2. Error Handling (CRITICAL)
err-thiserror-lib- Usethiserrorfor library error typeserr-anyhow-app- Useanyhowfor application error handlingerr-result-over-panic- ReturnResult, don't panic on expected errorserr-context-chain- Add context with.context()or.with_context()err-no-unwrap-prod- Never use.unwrap()in production codeerr-expect-bugs-only- Use.expect()only for programming errorserr-question-mark- Use?operator for clean propagationerr-from-impl- Use#[from]for automatic error conversionerr-source-chain- Use#[source]to chain underlying errorserr-lowercase-msg- Error messages: lowercase, no trailing punctuationerr-doc-errors- Document errors with# Errorssectionerr-custom-type- Create custom error types, notBox<dyn Error>
3. Memory Optimization (CRITICAL)
mem-with-capacity- Usewith_capacity()when size is knownmem-smallvec- UseSmallVecfor usually-small collectionsmem-arrayvec- UseArrayVecfor bounded-size collectionsmem-box-large-variant- Box large enum variants to reduce type sizemem-boxed-slice- UseBox<[T]>instead ofVec<T>when fixedmem-thinvec- UseThinVecfor often-empty vectorsmem-clone-from- Useclone_from()to reuse allocationsmem-reuse-collections- Reuse collections withclear()in loopsmem-avoid-format- Avoidformat!()when string literals workmem-write-over-format- Usewrite!()instead offormat!()mem-arena-allocator- Use arena allocators for batch allocationsmem-zero-copy- Use zero-copy patterns with slices andBytesmem-compact-string- UseCompactStringfor small string optimizationmem-smaller-integers- Use smallest integer type that fitsmem-assert-type-size- Assert hot type sizes to prevent regressions
4. API Design (HIGH)
api-builder-pattern- Use Builder pattern for complex constructionapi-builder-must-use- Add#[must_use]to builder typesapi-newtype-safety- Use newtypes for type-safe distinctionsapi-typestate- Use typestate for compile-time state machinesapi-sealed-trait- Seal traits to prevent external implementationsapi-extension-trait- Use extension traits to add methods to foreign typesapi-parse-dont-validate- Parse into validated types at boundariesapi-impl-into- Acceptimpl Into<T>for flexible string inputsapi-impl-asref- Acceptimpl AsRef<T>for borrowed inputsapi-must-use- Add#[must_use]toResultreturning functionsapi-non-exhaustive- Use#[non_exhaustive]for future-proof enums/structsapi-from-not-into- ImplementFrom, notInto(auto-derived)api-default-impl- ImplementDefaultfor sensible defaultsapi-common-traits- ImplementDebug,Clone,PartialEqeagerlyapi-serde-optional- GateSerialize/Deserializebehind feature flag
5. Async/Await (HIGH)
async-tokio-runtime- Use Tokio for production async runtimeasync-no-lock-await- Never holdMutex/RwLockacross.awaitasync-spawn-blocking- Usespawn_blockingfor CPU-intensive workasync-tokio-fs- Usetokio::fsnotstd::fsin async codeasync-cancellation-token- UseCancellationTokenfor graceful shutdownasync-join-parallel- Usetokio::join!for parallel operationsasync-try-join- Usetokio::try_join!for fallible parallel opsasync-select-racing- Usetokio::select!for racing/timeoutsasync-bounded-channel- Use bounded channels for backpressureasync-mpsc-queue- Usempscfor work queuesasync-broadcast-pubsub- Usebroadcastfor pub/sub patternsasync-watch-latest- Usewatchfor latest-value sharingasync-oneshot-response- Useoneshotfor request/responseasync-joinset-structured- UseJoinSetfor dynamic task groupsasync-clone-before-await- Clone data before await, release locks
6. Compiler Optimization (HIGH)
opt-inline-small- Use#[inline]for small hot functionsopt-inline-always-rare- Use#[inline(always)]sparinglyopt-inline-never-cold- Use#[inline(never)]for cold pathsopt-cold-unlikely- Use#[cold]for error/unlikely pathsopt-likely-hint- Uselikely()/unlikely()for branch hintsopt-lto-release- Enable LTO in release buildsopt-codegen-units- Usecodegen-units = 1for max optimizationopt-pgo-profile- Use PGO for production buildsopt-target-cpu- Settarget-cpu=nativefor local buildsopt-bounds-check- Use iterators to avoid bounds checksopt-simd-portable- Use portable SIMD for data-parallel opsopt-cache-friendly- Design cache-friendly data layouts (SoA)
7. Naming Conventions (MEDIUM)
name-types-camel- UseUpperCamelCasefor types, traits, enumsname-variants-camel- UseUpperCamelCasefor enum variantsname-funcs-snake- Usesnake_casefor functions, methods, modulesname-consts-screaming- UseSCREAMING_SNAKE_CASEfor constants/staticsname-lifetime-short- Use short lowercase lifetimes:'a,'de,'srcname-type-param-single- Use single uppercase for type params:T,E,K,Vname-as-free-as_prefix: free reference conversionname-to-expensive-to_prefix: expensive conversionname-into-ownership-into_prefix: ownership transfer
Discussion
Product Hunt–style comments (not star reviews)- No comments yet — start the thread.
Ratings
4.6★★★★★42 reviews- ★★★★★Sofia Okafor· Dec 20, 2024
We added rust-skills from the explainx registry; install was straightforward and the SKILL.md answered most questions upfront.
- ★★★★★Aisha Perez· Dec 20, 2024
Registry listing for rust-skills matched our evaluation — installs cleanly and behaves as described in the markdown.
- ★★★★★Amelia Lopez· Nov 27, 2024
rust-skills has been reliable in day-to-day use. Documentation quality is above average for community skills.
- ★★★★★Arjun White· Nov 11, 2024
rust-skills reduced setup friction for our internal harness; good balance of opinion and flexibility.
- ★★★★★Sofia Mensah· Nov 11, 2024
rust-skills fits our agent workflows well — practical, well scoped, and easy to wire into existing repos.
- ★★★★★Kwame White· Oct 18, 2024
Solid pick for teams standardizing on skills: rust-skills is focused, and the summary matches what you get after install.
- ★★★★★Aisha Smith· Oct 2, 2024
Registry listing for rust-skills matched our evaluation — installs cleanly and behaves as described in the markdown.
- ★★★★★Soo Malhotra· Oct 2, 2024
We added rust-skills from the explainx registry; install was straightforward and the SKILL.md answered most questions upfront.
- ★★★★★Amelia Taylor· Sep 21, 2024
Keeps context tight: rust-skills is the kind of skill you can hand to a new teammate without a long onboarding doc.
- ★★★★★Noah Ghosh· Sep 13, 2024
We added rust-skills from the explainx registry; install was straightforward and the SKILL.md answered most questions upfront.
showing 1-10 of 42