Now liveThe Skillselion MCP - thousands of ranked skills, loaded into your agent mid-task. No install.Get it →
actionbook avatar

M15 Anti Pattern

  • 1.4k installs
  • 1.3k repo stars
  • Updated May 24, 2026
  • actionbook/rust-skills

This is a copy of m15-anti-pattern by zhanghandong - installs and ranking accrue to the original listing.

m15-anti-pattern is a Rust code-review skill that flags ownership clones, unnecessary Box allocations, error-handling shortcuts, and performance mistakes with concrete before-and-after fixes for developers who ship Rust

About

m15-anti-pattern is a Rust anti-pattern reference skill that walks an agent through common ownership, error-handling, and performance mistakes with side-by-side bad and corrected examples. The skill covers patterns such as cloning to satisfy the borrow checker, boxing values unnecessarily, and other review-time smells called out in the actionbook/rust-skills repository. Developers reach for m15-anti-pattern when Rust compiles but feels slower than expected, when clones proliferate in hot paths, or when a PR needs structured guidance before human review. The excerpts document multiple named anti-patterns with runnable Rust snippets, making the output actionable during ship-phase review rather than generic style advice.

  • Identifies 15+ Rust anti-patterns with concrete before/after examples
  • Focuses on Ownership, Error Handling, and Performance categories
  • Provides ready-to-apply idiomatic replacements for each pattern
  • Hard-gate: run before any Rust code is committed or reviewed
  • Next-skill handoff: feeds cleaned code into automated testing workflow

M15 Anti Pattern by the numbers

  • 1,448 all-time installs (skills.sh)
  • +51 installs in the week ending Jul 28, 2026 (Skillselion tracking)
  • Security screen: LOW risk (skills.sh audit)
  • Data as of Jul 28, 2026 (Skillselion catalog sync)
npx skills add https://github.com/actionbook/rust-skills --skill m15-anti-pattern

Add your badge

Show developers this skill is listed on Skillselion. Paste this into your README.

Listed on Skillselion
Installs1.4k
repo stars1.3k
Security audit3 / 3 scanners passed
Last updatedMay 24, 2026
Repositoryactionbook/rust-skills

How do you catch common Rust anti-patterns before code review?

Automatically detect and suggest fixes for common Rust mistakes around ownership, error handling, and performance before code review or merge.

Who is it for?

Rust backend or systems developers who want automated anti-pattern review on ownership, errors, and performance before merge.

Skip if: Developers who need greenfield Rust architecture design or crate selection guidance rather than line-level anti-pattern fixes.

When should I use this skill?

A developer asks to review Rust for clones, Box misuse, error-handling smells, or performance anti-patterns before merge.

What you get

Annotated Rust diffs, borrow-friendly alternatives, and a pre-merge checklist of ownership and performance fixes.

  • Anti-pattern report
  • Corrected Rust snippets
  • Pre-merge review notes

By the numbers

  • Documents multiple named ownership anti-patterns with runnable Rust before/after examples

Files

SKILL.mdMarkdownGitHub ↗

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-PatternWhy BadBetter
.clone() everywhereHides ownership issuesProper references or ownership
.unwrap() in productionRuntime panics?, expect, or handling
Rc when single ownerUnnecessary overheadSimple ownership
unsafe for convenienceUB riskFind safe pattern
OOP via DerefMisleading APIComposition, traits
Giant match armsUnmaintainableExtract to methods
String everywhereAllocation waste&str, Cow<str>
Ignoring #[must_use]Lost errorsHandle 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

2. What would idiomatic code look like?

  • References instead of clones
  • Iterators instead of index loops
  • Pattern matching instead of flags

3. 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-PatternTrace ToQuestion
Clone everywherem01-ownershipWho should own this data?
Unwrap everywherem06-error-handlingWhat's the error strategy?
Rc everywherem09-domainIs ownership clear?
Fighting lifetimesm09-domainShould 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

RankMistakeFix
1Clone to escape borrow checkerUse references
2Unwrap in productionPropagate with ?
3String for everythingUse &str
4Index loopsUse iterators
5Fighting lifetimesRestructure to own data

Code Smell → Refactoring

SmellIndicatesRefactoring
Many .clone()Ownership unclearClarify data flow
Many .unwrap()Error handling missingAdd proper handling
Many pub fieldsEncapsulation brokenPrivate + accessors
Deep nestingComplex logicExtract methods
Long functionsMultiple responsibilitiesSplit
Giant enumsMissing abstractionTrait + types

---

Common Error Patterns

ErrorAnti-Pattern CauseFix
E0382 use after moveCloning vs ownershipProper references
Panic in productionUnwrap everywhere?, matching
Slow performanceString for all text&str, Cow
Borrow checker fightsWrong structureRestructure
Memory bloatRc/Arc everywhereSimple ownership

---

Deprecated → Better

DeprecatedBetter
Index-based loops.iter(), .enumerate()
collect::<Vec<_>>() then iterateChain iterators
Manual unsafe cellCell, RefCell
mem::transmute for castsas or TryFrom
Custom linked listVec, 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

WhenSee
Ownership patternsm01-ownership
Error handlingm06-error-handling
Mental modelsm14-mental-model
Performancem10-performance

Related skills

How it compares

Use for Rust-specific ownership and performance smells when generic linters pass but review feedback would still flag clones and unnecessary Box returns.

FAQ

What Rust mistakes does m15-anti-pattern detect?

m15-anti-pattern detects common Rust anti-patterns around ownership, error handling, and performance, including cloning to avoid the borrow checker and boxing values unnecessarily. Each pattern includes a bad example and a corrected Rust snippet developers can apply before merge.

When should developers invoke m15-anti-pattern?

Developers should invoke m15-anti-pattern before code review or merge when Rust compiles but shows excessive clones, Box usage, or error-handling shortcuts. The skill is designed for ship-phase review rather than initial project scaffolding.

Is M15 Anti Pattern safe to install?

skills.sh reports 3 of 3 security scanners passed. Review the Security Audits panel on this page before installing in production.

Code Review & Qualitybackendtesting

This week in AI coding

Five minutes, every Monday - the tools, releases and tactics for developers.

unsubscribe anytime.