โ† Back to list
rustfs

m15-anti-pattern

by rustfs

๐Ÿš€2.3x faster than MinIO for 4KB object payloads. RustFS is an open-source, S3-compatible high-performance object storage system supporting migration and coexistence with other S3-compatible platforms such as MinIO and Ceph.

โญ 20,125๐Ÿด 866๐Ÿ“… Jan 23, 2026

SKILL.md


name: m15-anti-pattern description: "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, ๅๆจกๅผ, ๅธธ่ง้”™่ฏฏ, ไปฃ็ ๅผ‚ๅ‘ณ, ๆœ€ไฝณๅฎž่ทต, ๅœฐ้“ๅ†™ๆณ•"

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)

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

Score

Total Score

90/100

Based on repository quality metrics

โœ“SKILL.md

SKILL.mdใƒ•ใ‚กใ‚คใƒซใŒๅซใพใ‚Œใฆใ„ใ‚‹

+20
โœ“LICENSE

ใƒฉใ‚คใ‚ปใƒณใ‚นใŒ่จญๅฎšใ•ใ‚Œใฆใ„ใ‚‹

+10
โœ“่ชฌๆ˜Žๆ–‡

100ๆ–‡ๅญ—ไปฅไธŠใฎ่ชฌๆ˜ŽใŒใ‚ใ‚‹

+10
โœ“ไบบๆฐ—

GitHub Stars 1000ไปฅไธŠ

+15
โœ“ๆœ€่ฟ‘ใฎๆดปๅ‹•

1ใƒถๆœˆไปฅๅ†…ใซๆ›ดๆ–ฐ

+10
โœ“ใƒ•ใ‚ฉใƒผใ‚ฏ

10ๅ›žไปฅไธŠใƒ•ใ‚ฉใƒผใ‚ฏใ•ใ‚Œใฆใ„ใ‚‹

+5
โ—‹Issue็ฎก็†

ใ‚ชใƒผใƒ—ใƒณIssueใŒ50ๆœชๆบ€

0/5
โœ“่จ€่ชž

ใƒ—ใƒญใ‚ฐใƒฉใƒŸใƒณใ‚ฐ่จ€่ชžใŒ่จญๅฎšใ•ใ‚Œใฆใ„ใ‚‹

+5
โœ“ใ‚ฟใ‚ฐ

1ใคไปฅไธŠใฎใ‚ฟใ‚ฐใŒ่จญๅฎšใ•ใ‚Œใฆใ„ใ‚‹

+5

Reviews

๐Ÿ’ฌ

Reviews coming soon