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