๐ŸŽฏ

m15-anti-pattern

๐ŸŽฏSkill

from goooice/rust-skills

VibeIndex|
What it does

Identifies and guides developers to replace common Rust anti-patterns with idiomatic, safe, and performant code design practices.

๐Ÿ“ฆ

Part of

goooice/rust-skills(35 items)

m15-anti-pattern

Installation

Add MarketplaceAdd marketplace to Claude Code
/plugin marketplace add ZhangHanDong/rust-skills
Install PluginInstall plugin from marketplace
/plugin install rust-skills@rust-skills
Quick InstallInstall with npx
npx skills add ZhangHanDong/rust-skills
git cloneClone repository
git clone https://github.com/ZhangHanDong/rust-skills.git
๐Ÿ“– Extracted from docs: goooice/rust-skills
4Installs
-
AddedFeb 4, 2026

Skill Details

SKILL.md

"Use when reviewing code for anti-patterns. Keywords: anti-pattern, common mistake, pitfall, code smell, bad practice, code review, is this an anti-pattern, better way to do this, common mistake to avoid, why is this bad, idiomatic way, beginner mistake, fighting borrow checker, clone everywhere, unwrap in production, should I refactor, ๅๆจกๅผ, ๅธธ่ง้”™่ฏฏ, ไปฃ็ ๅผ‚ๅ‘ณ, ๆœ€ไฝณๅฎž่ทต, ๅœฐ้“ๅ†™ๆณ•"

Overview

# Anti-Patterns

> Layer 2: Design Choices

Core Question

Is this pattern hiding a design problem?

When reviewing code:

  • Is this solving the symptom or the cause?
  • Is there a more idiomatic approach?
  • Does this fight or flow with Rust?

---

Anti-Pattern โ†’ Better Pattern

| Anti-Pattern | Why Bad | Better |

|--------------|---------|--------|

| .clone() everywhere | Hides ownership issues | Proper references or ownership |

| .unwrap() in production | Runtime panics | ?, expect, or handling |

| Rc when single owner | Unnecessary overhead | Simple ownership |

| unsafe for convenience | UB risk | Find safe pattern |

| OOP via Deref | Misleading API | Composition, traits |

| Giant match arms | Unmaintainable | Extract to methods |

| String everywhere | Allocation waste | &str, Cow |

| Ignoring #[must_use] | Lost errors | Handle or let _ = |

---

Thinking Prompt

When seeing suspicious code:

  1. Is this symptom or cause?

- Clone to avoid borrow? โ†’ Ownership design issue

- Unwrap "because it won't fail"? โ†’ Unhandled case

  1. What would idiomatic code look like?

- References instead of clones

- Iterators instead of index loops

- Pattern matching instead of flags

  1. Does this fight Rust?

- Fighting borrow checker โ†’ restructure

- Excessive unsafe โ†’ find safe pattern

---

Trace Up โ†‘

To design understanding:

```

"Why does my code have so many clones?"

โ†‘ Ask: Is the ownership model correct?

โ†‘ Check: m09-domain (data flow design)

โ†‘ Check: m01-ownership (reference patterns)

```

| Anti-Pattern | Trace To | Question |

|--------------|----------|----------|

| Clone everywhere | m01-ownership | Who should own this data? |

| Unwrap everywhere | m06-error-handling | What's the error strategy? |

| Rc everywhere | m09-domain | Is ownership clear? |

| Fighting lifetimes | m09-domain | Should data structure change? |

---

Trace Down โ†“

To implementation (Layer 1):

```

"Replace clone with proper ownership"

โ†“ m01-ownership: Reference patterns

โ†“ m02-resource: Smart pointer if needed

"Replace unwrap with proper handling"

โ†“ m06-error-handling: ? operator

โ†“ m06-error-handling: expect with message

```

---

Top 5 Beginner Mistakes

| Rank | Mistake | Fix |

|------|---------|-----|

| 1 | Clone to escape borrow checker | Use references |

| 2 | Unwrap in production | Propagate with ? |

| 3 | String for everything | Use &str |

| 4 | Index loops | Use iterators |

| 5 | Fighting lifetimes | Restructure to own data |

Code Smell โ†’ Refactoring

| Smell | Indicates | Refactoring |

|-------|-----------|-------------|

| Many .clone() | Ownership unclear | Clarify data flow |

| Many .unwrap() | Error handling missing | Add proper handling |

| Many pub fields | Encapsulation broken | Private + accessors |

| Deep nesting | Complex logic | Extract methods |

| Long functions | Multiple responsibilities | Split |

| Giant enums | Missing abstraction | Trait + types |

---

Common Error Patterns

| Error | Anti-Pattern Cause | Fix |

|-------|-------------------|-----|

| E0382 use after move | Cloning vs ownership | Proper references |

| Panic in production | Unwrap everywhere | ?, matching |

| Slow performance | String for all text | &str, Cow |

| Borrow checker fights | Wrong structure | Restructure |

| Memory bloat | Rc/Arc everywhere | Simple ownership |

---

Deprecated โ†’ Better

| Deprecated | Better |

|------------|--------|

| Index-based loops | .iter(), .enumerate() |

| collect::>() then iterate | Chain iterators |

| Manual unsafe cell | Cell, RefCell |

| mem::transmute for casts | as or TryFrom |

| Custom linked list | Vec, VecDeque |

| lazy_static! | std::sync::OnceLock |

---

Quick Review Checklist

  • [ ] No .clone() without justification
  • [ ] No .unwrap() in library code
  • [ ] No pub fields with invariants
  • [ ] No index loops when iterator works
  • [ ] No String where &str suffices
  • [ ] No ignored #[must_use] warnings
  • [ ] No unsafe without SAFETY comment
  • [ ] No giant functions (>50 lines)

---

Related Skills

| When | See |

|------|-----|

| Ownership patterns | m01-ownership |

| Error handling | m06-error-handling |

| Mental models | m14-mental-model |

| Performance | m10-performance |

More from this repository10

๐ŸŽฏ
m10-performance๐ŸŽฏSkill

Optimizes code performance by identifying bottlenecks, measuring impact, and guiding strategic improvements across algorithm, data structure, and memory efficiency.

๐ŸŽฏ
m14-mental-model๐ŸŽฏSkill

Applies the M14 mental model framework to enhance decision-making and strategic thinking through structured cognitive analysis.

๐ŸŽฏ
m04-zero-cost๐ŸŽฏSkill

Guides developers in choosing zero-cost abstractions by analyzing type system constraints and performance trade-offs in Rust generics and traits.

๐ŸŽฏ
meta-cognition-parallel๐ŸŽฏSkill

Performs parallel three-layer meta-cognitive analysis by forking subagents to simultaneously analyze language mechanics, design choices, and domain constraints, then synthesizing results.

๐ŸŽฏ
unsafe-checker๐ŸŽฏSkill

Identifies and reviews unsafe Rust code patterns, FFI risks, and potential memory unsafety in Rust projects.

๐ŸŽฏ
rust-skill-creator๐ŸŽฏSkill

Dynamically generates Claude skills for Rust crates, standard library modules, and documentation by extracting and processing technical details from specified URLs.

๐ŸŽฏ
coding-guidelines๐ŸŽฏSkill

Provides comprehensive Rust coding guidelines covering naming conventions, best practices, error handling, memory management, concurrency, and code style recommendations.

๐ŸŽฏ
rust-refactor-helper๐ŸŽฏSkill

Performs safe Rust refactoring by analyzing symbol references, checking conflicts, and applying changes across project files using LSP.

๐ŸŽฏ
m03-mutability๐ŸŽฏSkill

Diagnoses and guides resolution of Rust mutability and borrowing conflicts by analyzing ownership, mutation patterns, and thread-safety requirements.

๐ŸŽฏ
m05-type-driven๐ŸŽฏSkill

Explores and demonstrates type-driven development techniques in Rust, showcasing advanced type system features and pattern matching strategies.