Comprehensive performance optimization guide for Rust applications. Contains 42 rules across 8 categories, prioritized by impact to guide automated refactoring and code generation.
When to Apply
Reference these guidelines when:
Writing new Rust code
Optimizing memory allocation and ownership patterns
comp-use-const-generics-for-array-sizes - Use const generics for array sizes
comp-avoid-repeated-parsing-of-static-data - Avoid repeated parsing of static data
8. Micro-optimizations (LOW)
micro-use-inline-for-small-functions - Apply inline attribute to small hot functions
micro-avoid-bounds-checks-in-hot-loops - Avoid bounds checks in hot loops
micro-use-wrapping-arithmetic-when-safe - Use wrapping arithmetic when safe
micro-use-byte-literals-for-ascii - Use byte literals for ASCII
How to Use
Read individual reference files for detailed explanations and code examples:
Section definitions - Category structure and impact levels
Rule template - Template for adding new rules
Full Compiled Document
For a comprehensive guide with all rules in a single document, see AGENTS.md.
Reference Files
File
Description
AGENTS.md
Complete compiled guide with all rules
references/_sections.md
Category definitions and ordering
assets/templates/_template.md
Template for new rules
metadata.json
Version and reference information
1---2name: rust3description: Community Rust Best Practices4---5# Community Rust Best Practices67Comprehensive performance optimization guide for Rust applications. Contains 42 rules across 8 categories, prioritized by impact to guide automated refactoring and code generation.89## When to Apply1011Reference these guidelines when:12- Writing new Rust code13- Optimizing memory allocation and ownership patterns14- Working with iterators and collections15- Writing async code with Tokio or other runtimes16- Reviewing code for performance issues1718## Rule Categories by Priority1920| Priority | Category | Impact | Prefix |21|----------|----------|--------|--------|22| 1 | Memory Allocation | CRITICAL | `mem-` |23| 2 | Ownership & Borrowing | CRITICAL | `own-` |24| 3 | Data Structure Selection | HIGH | `ds-` |25| 4 | Iterator & Collection Patterns | HIGH | `iter-` |26| 5 | Async & Concurrency | MEDIUM-HIGH | `async-` |27| 6 | Algorithm Complexity | MEDIUM | `algo-` |28| 7 | Compile-Time Optimization | MEDIUM | `comp-` |29| 8 | Micro-optimizations | LOW | `micro-` |3031## Quick Reference3233### 1. Memory Allocation (CRITICAL)3435- [`mem-avoid-unnecessary-clone`](references/mem-avoid-unnecessary-clone.md) - Avoid unnecessary clone calls36- [`mem-preallocate-vec-capacity`](references/mem-preallocate-vec-capacity.md) - Preallocate Vec capacity37- [`mem-use-cow-for-conditional-ownership`](references/mem-use-cow-for-conditional-ownership.md) - Use Cow for conditional ownership38- [`mem-use-arc-for-shared-immutable-data`](references/mem-use-arc-for-shared-immutable-data.md) - Use Arc for shared immutable data39- [`mem-avoid-format-for-simple-concatenation`](references/mem-avoid-format-for-simple-concatenation.md) - Avoid format! for simple concatenation40- [`mem-use-smallvec-for-small-collections`](references/mem-use-smallvec-for-small-collections.md) - Use SmallVec for small collections4142### 2. Ownership & Borrowing (CRITICAL)4344- [`own-accept-str-slice-not-string`](references/own-accept-str-slice-not-string.md) - Accept &str instead of &String45- [`own-accept-slice-not-vec`](references/own-accept-slice-not-vec.md) - Accept &[T] instead of &Vec<T>46- [`own-use-into-for-flexible-ownership`](references/own-use-into-for-flexible-ownership.md) - Use Into<T> for flexible ownership47- [`own-return-borrowed-when-possible`](references/own-return-borrowed-when-possible.md) - Return borrowed data when possible48- [`own-use-asref-for-generic-borrows`](references/own-use-asref-for-generic-borrows.md) - Use AsRef<T> for generic borrows4950### 3. Data Structure Selection (HIGH)5152- [`ds-use-hashset-for-membership`](references/ds-use-hashset-for-membership.md) - Use HashSet for membership tests53- [`ds-use-hashmap-for-key-lookup`](references/ds-use-hashmap-for-key-lookup.md) - Use HashMap for key-value lookups54- [`ds-use-btreemap-for-sorted-iteration`](references/ds-use-btreemap-for-sorted-iteration.md) - Use BTreeMap for sorted iteration55- [`ds-use-vecdeque-for-queue-operations`](references/ds-use-vecdeque-for-queue-operations.md) - Use VecDeque for queue operations56- [`ds-use-entry-api-for-conditional-insert`](references/ds-use-entry-api-for-conditional-insert.md) - Use Entry API for conditional insert5758### 4. Iterator & Collection Patterns (HIGH)5960- [`iter-chain-instead-of-intermediate-collect`](references/iter-chain-instead-of-intermediate-collect.md) - Chain iterators instead of intermediate collect61- [`iter-use-iter-over-into-iter-when-borrowing`](references/iter-use-iter-over-into-iter-when-borrowing.md) - Use iter() over into_iter() when borrowing62- [`iter-use-filter-map-for-combined-operations`](references/iter-use-filter-map-for-combined-operations.md) - Use filter_map for combined operations63- [`iter-use-flat-map-for-nested-iteration`](references/iter-use-flat-map-for-nested-iteration.md) - Use flat_map for nested iteration64- [`iter-use-extend-for-bulk-append`](references/iter-use-extend-for-bulk-append.md) - Use extend() for bulk append65- [`iter-use-fold-for-accumulation`](references/iter-use-fold-for-accumulation.md) - Use fold() for complex accumulation6667### 5. Async & Concurrency (MEDIUM-HIGH)6869- [`async-avoid-blocking-in-async-context`](references/async-avoid-blocking-in-async-context.md) - Avoid blocking in async context70- [`async-use-join-for-concurrent-futures`](references/async-use-join-for-concurrent-futures.md) - Use join! for concurrent futures71- [`async-use-rwlock-over-mutex-for-read-heavy`](references/async-use-rwlock-over-mutex-for-read-heavy.md) - Use RwLock over Mutex for read-heavy72- [`async-minimize-lock-scope`](references/async-minimize-lock-scope.md) - Minimize lock scope73- [`async-use-buffered-for-bounded-concurrency`](references/async-use-buffered-for-bounded-concurrency.md) - Use buffered() for bounded concurrency74- [`async-avoid-holding-lock-across-await`](references/async-avoid-holding-lock-across-await.md) - Avoid holding lock across await7576### 6. Algorithm Complexity (MEDIUM)7778- [`algo-avoid-nested-loops-for-lookup`](references/algo-avoid-nested-loops-for-lookup.md) - Avoid nested loops for lookups79- [`algo-use-binary-search-for-sorted-data`](references/algo-use-binary-search-for-sorted-data.md) - Use binary search for sorted data80- [`algo-use-sort-unstable-when-order-irrelevant`](references/algo-use-sort-unstable-when-order-irrelevant.md) - Use sort_unstable when order irrelevant81- [`algo-use-select-nth-unstable-for-partial-sort`](references/algo-use-select-nth-unstable-for-partial-sort.md) - Use select_nth_unstable for partial sort82- [`algo-use-chunks-for-batch-processing`](references/algo-use-chunks-for-batch-processing.md) - Use chunks() for batch processing8384### 7. Compile-Time Optimization (MEDIUM)8586- [`comp-use-const-for-compile-time-computation`](references/comp-use-const-for-compile-time-computation.md) - Use const for compile-time computation87- [`comp-prefer-static-dispatch`](references/comp-prefer-static-dispatch.md) - Prefer static dispatch over dynamic88- [`comp-reduce-monomorphization-bloat`](references/comp-reduce-monomorphization-bloat.md) - Reduce monomorphization bloat89- [`comp-use-const-generics-for-array-sizes`](references/comp-use-const-generics-for-array-sizes.md) - Use const generics for array sizes90- [`comp-avoid-repeated-parsing-of-static-data`](references/comp-avoid-repeated-parsing-of-static-data.md) - Avoid repeated parsing of static data9192### 8. Micro-optimizations (LOW)9394- [`micro-use-inline-for-small-functions`](references/micro-use-inline-for-small-functions.md) - Apply inline attribute to small hot functions95- [`micro-avoid-bounds-checks-in-hot-loops`](references/micro-avoid-bounds-checks-in-hot-loops.md) - Avoid bounds checks in hot loops96- [`micro-use-wrapping-arithmetic-when-safe`](references/micro-use-wrapping-arithmetic-when-safe.md) - Use wrapping arithmetic when safe97- [`micro-use-byte-literals-for-ascii`](references/micro-use-byte-literals-for-ascii.md) - Use byte literals for ASCII9899## How to Use100101Read individual reference files for detailed explanations and code examples:102103- [Section definitions](references/_sections.md) - Category structure and impact levels104- [Rule template](assets/templates/_template.md) - Template for adding new rules105106## Full Compiled Document107108For a comprehensive guide with all rules in a single document, see [AGENTS.md](AGENTS.md).109110## Reference Files111112| File | Description |113|------|-------------|114| [AGENTS.md](AGENTS.md) | Complete compiled guide with all rules |115| [references/_sections.md](references/_sections.md) | Category definitions and ordering |116| [assets/templates/_template.md](assets/templates/_template.md) | Template for new rules |117| [metadata.json](metadata.json) | Version and reference information |
Run npx skillmds@latest add comeonoliver/rust in your terminal (requires Node.js), paste this page's agent-chat prompt into Claude, Cursor, or any MCP-connected agent, or download the SKILL.md file and copy it into your agent's skills directory.
Community Rust Best Practices It is listed under Coding & Dev Tools on SkillMD.
This skill has not completed SkillMD's automated safety review yet. Independent scanners report: SkillSpector: PASS, Skill Scanner: PASS. SkillMD never runs a skill's scripts for you; review the SKILL.md before installing.
This skill is tagged as working with Claude Code, Claude.ai, OpenAI Codex. SKILL.md is an open format, so most agents that read a skills directory can load it too.
Yes. Installing skills from SkillMD is free, and the skill stays under its author's original license.
ComeOnOliver (@comeonoliver) published this skill. Their other Agent Skills are listed on their SkillMD profile.