m11-ecosystem
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseCurrent Dependencies (Auto-Injected)
当前依赖项(自动注入)
!
grep -A 100 '^\[dependencies\]' Cargo.toml 2>/dev/null | head -30 || echo "No Cargo.toml found"!
grep -A 100 '^\[dependencies\]' Cargo.toml 2>/dev/null | head -30 || echo "No Cargo.toml found"Ecosystem Integration
生态系统集成
Layer 2: Design Choices
第二层:设计选择
Core Question
核心问题
What's the right crate for this job, and how should it integrate?
Before adding dependencies:
- Is there a standard solution?
- What's the maintenance status?
- What's the API stability?
完成这项工作应该选择哪个crate,又该如何集成它?
添加依赖项之前:
- 是否有标准解决方案?
- 维护状态如何?
- API稳定性如何?
Integration Decision → Implementation
集成决策 → 实现
| Need | Choice | Crates |
|---|---|---|
| Serialization | Derive-based | serde, serde_json |
| Async runtime | tokio or async-std | tokio (most popular) |
| HTTP client | Ergonomic | reqwest |
| HTTP server | Modern | axum, actix-web |
| Database | SQL or ORM | sqlx, diesel |
| CLI parsing | Derive-based | clap |
| Error handling | App vs lib | anyhow, thiserror |
| Logging | Facade | tracing, log |
| 需求 | 选择方案 | Crate |
|---|---|---|
| 序列化 | 基于派生 | serde, serde_json |
| 异步运行时 | tokio 或 async-std | tokio(最受欢迎) |
| HTTP客户端 | 易用性优先 | reqwest |
| HTTP服务器 | 现代化框架 | axum, actix-web |
| 数据库 | SQL或ORM | sqlx, diesel |
| CLI解析 | 基于派生 | clap |
| 错误处理 | 应用 vs 库 | anyhow, thiserror |
| 日志 | 门面模式 | tracing, log |
Thinking Prompt
思考提示
Before adding a dependency:
-
Is it well-maintained?
- Recent commits?
- Active issue response?
- Breaking changes frequency?
-
What's the scope?
- Do you need the full crate or just a feature?
- Can feature flags reduce bloat?
-
How does it integrate?
- Trait-based or concrete types?
- Sync or async?
- What bounds does it require?
添加依赖项之前:
-
维护情况是否良好?
- 近期是否有提交记录?
- 问题反馈是否积极响应?
- 破坏性变更频率如何?
-
功能范围是否匹配?
- 你需要完整的crate还是仅部分功能?
- 能否通过feature flag减少冗余?
-
集成方式是否适配?
- 基于 trait 还是具体类型?
- 同步还是异步?
- 有哪些约束条件?
Trace Up ↑
向上追溯 ↑
To domain constraints (Layer 3):
"Which HTTP framework should I use?"
↑ Ask: What are the performance requirements?
↑ Check: domain-web (latency, throughput needs)
↑ Check: Team expertise (familiarity with framework)| Question | Trace To | Ask |
|---|---|---|
| Framework choice | domain-* | What constraints matter? |
| Library vs build | domain-* | What's the deployment model? |
| API design | domain-* | Who are the consumers? |
到领域约束(第三层):
"我应该使用哪个HTTP框架?"
↑ 提问:性能要求是什么?
↑ 检查:domain-web(延迟、吞吐量需求)
↑ 检查:团队技术栈(对框架的熟悉程度)| 问题 | 追溯方向 | 提问内容 |
|---|---|---|
| 框架选择 | domain-* | 哪些约束条件是关键? |
| 库 vs 构建 | domain-* | 部署模型是什么? |
| API设计 | domain-* | 使用者是谁? |
Trace Down ↓
向下追溯 ↓
To implementation (Layer 1):
"Integrate external crate"
↓ m04-zero-cost: Trait bounds and generics
↓ m06-error-handling: Error type compatibility
"FFI integration"
↓ unsafe-checker: Safety requirements
↓ m12-lifecycle: Resource cleanup到实现层(第一层):
"集成外部crate"
↓ m04-zero-cost:Trait约束与泛型
↓ m06-error-handling:错误类型兼容性
"FFI集成"
↓ unsafe-checker:安全性要求
↓ m12-lifecycle:资源清理Quick Reference
快速参考
Language Interop
语言互操作
| Integration | Crate/Tool | Use Case |
|---|---|---|
| C/C++ → Rust | | Auto-generate bindings |
| Rust → C | | Export C headers |
| Python ↔ Rust | | Python extensions |
| Node.js ↔ Rust | | Node addons |
| WebAssembly | | Browser/WASI |
| 集成场景 | Crate/工具 | 适用案例 |
|---|---|---|
| C/C++ → Rust | | 自动生成绑定 |
| Rust → C | | 导出C头文件 |
| Python ↔ Rust | | Python扩展 |
| Node.js ↔ Rust | | Node扩展 |
| WebAssembly | | 浏览器/WASI环境 |
Cargo Features
Cargo特性
| Feature | Purpose |
|---|---|
| Optional functionality |
| Default features |
| Conditional deps |
| Multi-crate projects |
| 特性 | 用途 |
|---|---|
| 可选功能模块 |
| 默认启用的特性 |
| 条件依赖 |
| 多crate项目管理 |
Error Code Reference
错误码参考
| Error | Cause | Fix |
|---|---|---|
| E0433 | Can't find crate | Add to Cargo.toml |
| E0603 | Private item | Check crate docs |
| Feature not enabled | Optional feature | Enable in |
| Version conflict | Incompatible deps | |
| Duplicate types | Different crate versions | Unify in workspace |
| 错误码 | 原因 | 修复方案 |
|---|---|---|
| E0433 | 无法找到crate | 添加至Cargo.toml |
| E0603 | 私有项访问 | 查看crate文档 |
| 特性未启用 | 使用了可选特性 | 在 |
| 版本冲突 | 依赖版本不兼容 | 执行 |
| 类型重复 | crate版本不一致 | 在工作空间中统一版本 |
Crate Selection Criteria
Crate选择标准
| Criterion | Good Sign | Warning Sign |
|---|---|---|
| Maintenance | Recent commits | Years inactive |
| Community | Active issues/PRs | No response |
| Documentation | Examples, API docs | Minimal docs |
| Stability | Semantic versioning | Frequent breaking |
| Dependencies | Minimal, well-known | Heavy, obscure |
| 评估标准 | 良好迹象 | 警示信号 |
|---|---|---|
| 维护状态 | 近期有提交 | 多年未更新 |
| 社区活跃度 | 问题/PR响应积极 | 无任何响应 |
| 文档质量 | 有示例、API文档完善 | 文档极简 |
| 版本稳定性 | 遵循语义化版本 | 频繁发布破坏性变更 |
| 依赖链 | 依赖少且都是知名库 | 依赖繁重且多为小众库 |
Anti-Patterns
反模式
| Anti-Pattern | Why Bad | Better |
|---|---|---|
| Outdated (2018+) | Just |
| Global pollution | Explicit import |
Wildcard deps | Unpredictable | Specific versions |
| Too many deps | Supply chain risk | Evaluate necessity |
| Vendoring everything | Maintenance burden | Trust crates.io |
| 反模式 | 危害 | 优化方案 |
|---|---|---|
| 已过时(2018年起) | 直接使用 |
| 全局污染 | 显式导入宏 |
通配符依赖 | 版本不可预测 | 指定具体版本 |
| 依赖过多 | 供应链风险 | 评估依赖必要性 |
| 手动 vendoring 所有依赖 | 维护负担重 | 信任crates.io上的库 |
Related Skills
相关技能
| When | See |
|---|---|
| Error type design | m06-error-handling |
| Trait integration | m04-zero-cost |
| FFI safety | unsafe-checker |
| Resource management | m12-lifecycle |
| 适用场景 | 参考内容 |
|---|---|
| 错误类型设计 | m06-error-handling |
| Trait集成 | m04-zero-cost |
| FFI安全性 | unsafe-checker |
| 资源管理 | m12-lifecycle |