huiali/rust-skills/rust-macro
Claude Code and agent skill by huiali/rust-skills
Trust tier 3
- community
Source check pending
Checking that the SKILL.md file is still in the repository.
Macro and procedural metaprogramming expert covering macro_rules!, derive macros, proc-macros, compile-time computation, and code generation patterns.
Install
npx vskill@latest install huiali/rust-skills/rust-macroSKILL.md
Macros vs Generics
| Dimension | Macros | Generics | |
|---|---|---|---|
| Flexibility | Code transformation | Type abstraction | |
| Compile cost | Incremental-friendly | Monomorphization overhead | |
| Error messages | Can be cryptic | Clear | |
| Debugging | Debug expanded code | Direct debugging | |
| Use case | Reduce boilerplate | Generic algorithms |
Solution Patterns
Pattern 1: Declarative Macro (macro_rules!)
Pattern 2: Derive Macro
Pattern 3: Function-like Proc Macro
Pattern 4: Attribute Macro
Repetition Patterns
| Syntax | Meaning | |
|---|---|---|
$() | Match zero or more | |
$($x),* | Comma-separated | |
$($x),+ | At least one | |
$x:ty | Type matcher | |
$x:expr | Expression matcher | |
$x:pat | Pattern matcher | |
$x:ident | Identifier matcher | |
$x:path | Path matcher | |
$x:tt | Token tree matcher |
Workflow
Step 1: Consider Alternatives
Step 2: Choose Macro Type
Step 3: Debug Expansion
Step 4: Test Thoroughly
Common Crates
| Crate | Purpose | |
|---|---|---|
| syn | Parse Rust syntax | |
| quote | Generate Rust code | |
| proc-macro2 | Token manipulation | |
| derive-more | Common derive macros | |
| darling | Parse macro attributes |
Best Practices
| Practice | Reason | |
|---|---|---|
| Try generics first | Safer, easier to debug | |
| Keep macros simple | Complex macros hard to maintain | |
| Document macros | Users need to understand expansion | |
| Test expansion | Ensure correctness | |
| Use cargo expand | Visualize macro output |
Review Checklist
When reviewing macro code:
- [ ] Could this be solved with generics instead?
- [ ] Macro expansion documented with examples
- [ ] Error messages are helpful
- [ ] Edge cases tested
- [ ] Hygiene respected (no accidental captures)
- [ ] Used cargo expand to verify output
- [ ] Compile-time overhead acceptable
- [ ] No unnecessary proc-macro dependency
Verification Commands
Common Pitfalls
1. Hygiene Violations
Symptom: Unexpected variable captures
2. Complex Error Messages
Symptom: Users don't understand macro errors
3. Proc Macro Compile Time
Symptom: Slow incremental builds
Related Skills
- rust-coding - Naming macro conventions
- rust-performance - Macro compile-time cost
- rust-type-driven - When generics suffice
- rust-error - Error handling in macros
- rust-testing - Testing macro expansion
Localized Reference
- Chinese version: SKILL_ZH.md - 完整中文版本,包含所有内容
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/rust-macro/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 21 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-macro)