huiali/rust-skills/rust-anti-pattern
Claude Code and agent skill by huiali/rust-skills
Trust tier 2
- community
Source check pending
Checking that the SKILL.md file is still in the repository.
Rust anti-patterns and common mistakes expert. Handles code review issues with clone abuse, unwrap in production, String misuse, index loops, and refactoring guidance.
Install
npx vskill@latest install huiali/rust-skills/rust-anti-patternSKILL.md
Top 5 Beginner Mistakes
| Rank | Mistake | Correct Approach | |
|---|---|---|---|
| 1 | Using .clone() to escape borrow checker | Use references | |
| 2 | Using .unwrap() in production code | Use ? or with_context() | |
| 3 | Everything is String | Use &str, Cow<str> when needed | |
| 4 | Index-based loops | Use iterators .iter(), .enumerate() | |
| 5 | Fighting lifetimes | Redesign data structure |
Common Anti-Patterns
Anti-Pattern 1: Clone Everywhere
When clone is actually needed:
- Truly need independent copy
- API design requires owned value
- Data flow requirements
Anti-Pattern 2: Unwrap in Production
Anti-Pattern 3: String Everywhere
Anti-Pattern 4: Index Loops
Anti-Pattern 5: Excessive Unsafe
Solution Patterns
Pattern 1: Avoiding Clone
Pattern 2: Proper Error Handling
Pattern 3: String vs &str
Pattern 4: Iterator-Based Processing
Code Smell Quick Reference
| Symptom | Indicates | Refactoring Direction | |
|---|---|---|---|
Many .clone() | Unclear ownership | Clarify data flow | |
Many .unwrap() | Missing error handling | Add Result handling | |
Many pub fields | Broken encapsulation | Private + accessors | |
| Deep nesting | Complex logic | Extract methods | |
| Long functions (>50 lines) | Too many responsibilities | Split responsibilities | |
| Huge enums | Missing abstraction | Trait + types |
Outdated → Modern Patterns
| Outdated | Modern | |
|---|---|---|
Index loop .items[i] | .iter().enumerate() | |
collect::<Vec<_>>() then iterate | Chain iterators | |
lazy_static! | std::sync::OnceLock | |
mem::transmute conversion | as or TryFrom | |
| Custom linked list | Vec or VecDeque | |
| Manual unsafe cell | Cell, RefCell |
Workflow
Step 1: Identify Anti-Patterns
Step 2: Ask Key Questions
Step 3: Refactor
Review Checklist
When reviewing code:
- [ ] No unreasonable
.clone() - [ ] Library code has no
.unwrap() - [ ] No
pubfields with invariants - [ ] No index loops when iterators available
- [ ] Using
&strinstead ofStringwhen sufficient - [ ] Not ignoring
#[must_use]warnings - [ ]
unsafehas SAFETY comments - [ ] No giant functions (>50 lines)
- [ ] Error handling uses Result not panic
- [ ] No premature optimization
Verification Commands
Common Pitfalls
1. Clone to Compile
Symptom: Lots of .clone() calls
2. Error Handling Shortcuts
Symptom: Unwrap/expect in production code
3. String Allocation Waste
Symptom: Unnecessary String allocations
Self-Check Questions
1. Is this code fighting Rust?
- Fighting → Redesign approach
- Working with → Continue
2. Is this clone necessary?
- To escape borrow checker → Warning sign
- Actually need independent copy → OK
3. Will this unwrap panic?
- Might panic → Use
? - Never panics →
expect("reason")
4. Is there a more idiomatic way?
- Reference other Rust codebases
- Check std library APIs
Related Skills
- rust-coding - Idiomatic patterns to follow
- rust-ownership - Understanding borrowing to avoid clones
- rust-error - Proper error handling patterns
- rust-performance - When optimization matters
- rust-refactoring - Systematic code improvement
Localized Reference
- Chinese version: SKILL_ZH.md - 完整中文版本,包含所有内容
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewNot runA model review is scheduled for the next rescan.
- semgrepPassed, 100 of 100
- njsscanPassed, 100 of 100
- trufflehogPassed, 100 of 100
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/rust-anti-pattern/SKILL.md
Popularity
- Repository stars
- 20
- Repository forks
- 4
- 7-day trend score
- 15
Stars and forks are for the whole GitHub repository, not this skill alone. Refreshed 22 Mar 2026, 7 months ago.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/huiali/rust-skills/rust-anti-pattern)