1---
2name: rust-router
3description: |-
4 CRITICAL: Use for ALL Rust questions including errors, design, and coding.
5 HIGHEST PRIORITY for: 比较, 对比, compare, vs, versus, 区别, difference, 最佳实践, best practice,
6 tokio vs, async-std vs, 比较 tokio, 比较 async,
7 Triggers on: Rust, cargo, rustc, crate, Cargo.toml,
8 意图分析, 问题分析, 语义分析, analyze intent, question analysis,
9 compile error, borrow error, lifetime error, ownership error, type error, trait error,
10 value moved, cannot borrow, does not live long enough, mismatched types, not satisfied,
11 E0382, E0597, E0277, E0308, E0499, E0502, E0596,
12 async, await, Send, Sync, tokio, concurrency, error handling,
13 编译错误, compile error, 所有权, ownership, 借用, borrow, 生命周期, lifetime, 类型错误, type error,
14 异步, async, 并发, concurrency, 错误处理, error handling,
15 问题, problem, question, 怎么用, how to use, 如何, how to, 为什么, why,
16 什么是, what is, 帮我写, help me write, 实现, implement, 解释, explain
17globs: ["**/Cargo.toml", "**/*.rs"]
18metadata:
19 source: https://skillmd.com/skills/om-scogo/rust-router
20---
21
22---
23
24# Rust Question Router
25
26> **Version:** 2.0.0 | **Last Updated:** 2025-01-22
27>
28> **v2.0:** Context optimized - detailed examples moved to sub-files
29
30## Meta-Cognition Framework
31
32### Core Principle
33
34**Don't answer directly. Trace through the cognitive layers first.**
35
36```
37Layer 3: Domain Constraints (WHY)
38├── Business rules, regulatory requirements
39├── domain-fintech, domain-web, domain-cli, etc.
40└── "Why is it designed this way?"
41
42Layer 2: Design Choices (WHAT)
43├── Architecture patterns, DDD concepts
44├── m09-m15 skills
45└── "What pattern should I use?"
46
47Layer 1: Language Mechanics (HOW)
48├── Ownership, borrowing, lifetimes, traits
49├── m01-m07 skills
50└── "How do I implement this in Rust?"
51```
52
53### Routing by Entry Point
54
55| User Signal | Entry Layer | Direction | First Skill |
56|-------------|-------------|-----------|-------------|
57| E0xxx error | Layer 1 | Trace UP ↑ | m01-m07 |
58| Compile error | Layer 1 | Trace UP ↑ | Error table below |
59| "How to design..." | Layer 2 | Check L3, then DOWN ↓ | m09-domain |
60| "Building [domain] app" | Layer 3 | Trace DOWN ↓ | domain-* |
61| "Best practice..." | Layer 2 | Both directions | m09-m15 |
62| Performance issue | Layer 1 → 2 | UP then DOWN | m10-performance |
63
64### CRITICAL: Dual-Skill Loading
65
66**When domain keywords are present, you MUST load BOTH skills:**
67
68| Domain Keywords | L1 Skill | L3 Skill |
69|-----------------|----------|----------|
70| Web API, HTTP, axum, handler | m07-concurrency | **domain-web** |
71| 交易, 支付, trading, payment | m01-ownership | **domain-fintech** |
72| CLI, terminal, clap | m07-concurrency | **domain-cli** |
73| kubernetes, grpc, microservice | m07-concurrency | **domain-cloud-native** |
74| embedded, no_std, MCU | m02-resource | **domain-embedded** |
75
76---
77
78## INSTRUCTIONS FOR CLAUDE
79
80### CRITICAL: Negotiation Protocol Trigger
81
82**BEFORE answering, check if negotiation is required:**
83
84| Query Contains | Action |
85|----------------|--------|
86| "比较", "对比", "compare", "vs", "versus" | **MUST use negotiation** |
87| "最佳实践", "best practice" | **MUST use negotiation** |
88| Domain + error (e.g., "交易系统 E0382") | **MUST use negotiation** |
89| Ambiguous scope (e.g., "tokio 性能") | **SHOULD use negotiation** |
90
91**When negotiation is required, include:**
92
93```markdown
94## Negotiation Analysis
95
96**Query Type:** [Comparative | Cross-domain | Synthesis | Ambiguous]
97**Negotiation:** Enabled
98
99### Source: [Agent/Skill Name]
100**Confidence:** HIGH | MEDIUM | LOW | UNCERTAIN
101**Gaps:** [What's missing]
102
103## Synthesized Answer
104[Answer]
105
106**Overall Confidence:** [Level]
107**Disclosed Gaps:** [Gaps user should know]
108```
109
110> **详细协议见:** `patterns/negotiation.md`
111
112---
113
114### Default Project Settings
115
116When creating new Rust projects or Cargo.toml files, ALWAYS use:
117
118```toml
119[package]
120edition = "2024" # ALWAYS use latest stable edition
121rust-version = "1.85"
122
123[lints.rust]
124unsafe_code = "warn"
125
126[lints.clippy]
127all = "warn"
128pedantic = "warn"
129```
130
131---
132
133## Layer 1 Skills (Language Mechanics)
134
135| Pattern | Route To |
136|---------|----------|
137| move, borrow, lifetime, E0382, E0597 | m01-ownership |
138| Box, Rc, Arc, RefCell, Cell | m02-resource |
139| mut, interior mutability, E0499, E0502, E0596 | m03-mutability |
140| generic, trait, inline, monomorphization | m04-zero-cost |
141| type state, phantom, newtype | m05-type-driven |
142| Result, Error, panic, ?, anyhow, thiserror | m06-error-handling |
143| Send, Sync, thread, async, channel | m07-concurrency |
144| unsafe, FFI, extern, raw pointer, transmute | **unsafe-checker** |
145
146## Layer 2 Skills (Design Choices)
147
148| Pattern | Route To |
149|---------|----------|
150| domain model, business logic | m09-domain |
151| performance, optimization, benchmark | m10-performance |
152| integration, interop, bindings | m11-ecosystem |
153| resource lifecycle, RAII, Drop | m12-lifecycle |
154| domain error, recovery strategy | m13-domain-error |
155| mental model, how to think | m14-mental-model |
156| anti-pattern, common mistake, pitfall | m15-anti-pattern |
157
158## Layer 3 Skills (Domain Constraints)
159
160| Domain Keywords | Route To |
161|-----------------|----------|
162| fintech, trading, decimal, currency | domain-fintech |
163| ml, tensor, model, inference | domain-ml |
164| kubernetes, docker, grpc, microservice | domain-cloud-native |
165| embedded, sensor, mqtt, iot | domain-iot |
166| web server, HTTP, REST, axum, actix | domain-web |
167| CLI, command line, clap, terminal | domain-cli |
168| no_std, microcontroller, firmware | domain-embedded |
169
170---
171
172## Error Code Routing
173
174| Error Code | Route To | Common Cause |
175|------------|----------|--------------|
176| E0382 | m01-ownership | Use of moved value |
177| E0597 | m01-ownership | Lifetime too short |
178| E0506 | m01-ownership | Cannot assign to borrowed |
179| E0507 | m01-ownership | Cannot move out of borrowed |
180| E0515 | m01-ownership | Return local reference |
181| E0716 | m01-ownership | Temporary value dropped |
182| E0106 | m01-ownership | Missing lifetime specifier |
183| E0596 | m03-mutability | Cannot borrow as mutable |
184| E0499 | m03-mutability | Multiple mutable borrows |
185| E0502 | m03-mutability | Borrow conflict |
186| E0277 | m04/m07 | Trait bound not satisfied |
187| E0308 | m04-zero-cost | Type mismatch |
188| E0599 | m04-zero-cost | No method found |
189| E0038 | m04-zero-cost | Trait not object-safe |
190| E0433 | m11-ecosystem | Cannot find crate/module |
191
192---
193
194## Functional Routing Table
195
196| Pattern | Route To | Action |
197|---------|----------|--------|
198| latest version, what's new | **rust-learner** | Use agents |
199| API, docs, documentation | **docs-researcher** | Use agent |
200| code style, naming, clippy | **coding-guidelines** | Read skill |
201| unsafe code, FFI | **unsafe-checker** | Read skill |
202| code review | **os-checker** | See `integrations/os-checker.md` |
203
204---
205
206## Priority Order
207
2081. **Identify cognitive layer** (L1/L2/L3)
2092. **Load entry skill** (m0x/m1x/domain)
2103. **Trace through layers** (UP or DOWN)
2114. **Cross-reference skills** as indicated in "Trace" sections
2125. **Answer with reasoning chain**
213
214### Keyword Conflict Resolution
215
216| Keyword | Resolution |
217|---------|------------|
218| `unsafe` | **unsafe-checker** (more specific than m11) |
219| `error` | **m06** for general, **m13** for domain-specific |
220| `RAII` | **m12** for design, **m01** for implementation |
221| `crate` | **rust-learner** for version, **m11** for integration |
222| `tokio` | **tokio-*** for API, **m07** for concepts |
223
224**Priority Hierarchy:**
225
226```
2271. Error codes (E0xxx) → Direct lookup, highest priority
2282. Negotiation triggers (compare, vs, best practice) → Enable negotiation
2293. Domain keywords + error → Load BOTH domain + error skills
2304. Specific crate keywords → Route to crate-specific skill if exists
2315. General concept keywords → Route to meta-question skill
232```
233
234---
235
236## Sub-Files Reference
237
238| File | Content |
239|------|---------|
240| `patterns/negotiation.md` | Negotiation protocol details |
241| `examples/workflow.md` | Workflow examples |
242| `integrations/os-checker.md` | OS-Checker integration |