m11-ecosystem

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Current 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

集成决策 → 实现

NeedChoiceCrates
SerializationDerive-basedserde, serde_json
Async runtimetokio or async-stdtokio (most popular)
HTTP clientErgonomicreqwest
HTTP serverModernaxum, actix-web
DatabaseSQL or ORMsqlx, diesel
CLI parsingDerive-basedclap
Error handlingApp vs libanyhow, thiserror
LoggingFacadetracing, log

需求选择方案Crate
序列化基于派生serde, serde_json
异步运行时tokio 或 async-stdtokio(最受欢迎)
HTTP客户端易用性优先reqwest
HTTP服务器现代化框架axum, actix-web
数据库SQL或ORMsqlx, diesel
CLI解析基于派生clap
错误处理应用 vs 库anyhow, thiserror
日志门面模式tracing, log

Thinking Prompt

思考提示

Before adding a dependency:
  1. Is it well-maintained?
    • Recent commits?
    • Active issue response?
    • Breaking changes frequency?
  2. What's the scope?
    • Do you need the full crate or just a feature?
    • Can feature flags reduce bloat?
  3. How does it integrate?
    • Trait-based or concrete types?
    • Sync or async?
    • What bounds does it require?

添加依赖项之前:
  1. 维护情况是否良好?
    • 近期是否有提交记录?
    • 问题反馈是否积极响应?
    • 破坏性变更频率如何?
  2. 功能范围是否匹配?
    • 你需要完整的crate还是仅部分功能?
    • 能否通过feature flag减少冗余?
  3. 集成方式是否适配?
    • 基于 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)
QuestionTrace ToAsk
Framework choicedomain-*What constraints matter?
Library vs builddomain-*What's the deployment model?
API designdomain-*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

语言互操作

IntegrationCrate/ToolUse Case
C/C++ → Rust
bindgen
Auto-generate bindings
Rust → C
cbindgen
Export C headers
Python ↔ Rust
pyo3
Python extensions
Node.js ↔ Rust
napi-rs
Node addons
WebAssembly
wasm-bindgen
Browser/WASI
集成场景Crate/工具适用案例
C/C++ → Rust
bindgen
自动生成绑定
Rust → C
cbindgen
导出C头文件
Python ↔ Rust
pyo3
Python扩展
Node.js ↔ Rust
napi-rs
Node扩展
WebAssembly
wasm-bindgen
浏览器/WASI环境

Cargo Features

Cargo特性

FeaturePurpose
[features]
Optional functionality
default = [...]
Default features
feature = "serde"
Conditional deps
[workspace]
Multi-crate projects
特性用途
[features]
可选功能模块
default = [...]
默认启用的特性
feature = "serde"
条件依赖
[workspace]
多crate项目管理

Error Code Reference

错误码参考

ErrorCauseFix
E0433Can't find crateAdd to Cargo.toml
E0603Private itemCheck crate docs
Feature not enabledOptional featureEnable in
features
Version conflictIncompatible deps
cargo update
or pin
Duplicate typesDifferent crate versionsUnify in workspace

错误码原因修复方案
E0433无法找到crate添加至Cargo.toml
E0603私有项访问查看crate文档
特性未启用使用了可选特性
features
中启用
版本冲突依赖版本不兼容执行
cargo update
或固定版本
类型重复crate版本不一致在工作空间中统一版本

Crate Selection Criteria

Crate选择标准

CriterionGood SignWarning Sign
MaintenanceRecent commitsYears inactive
CommunityActive issues/PRsNo response
DocumentationExamples, API docsMinimal docs
StabilitySemantic versioningFrequent breaking
DependenciesMinimal, well-knownHeavy, obscure

评估标准良好迹象警示信号
维护状态近期有提交多年未更新
社区活跃度问题/PR响应积极无任何响应
文档质量有示例、API文档完善文档极简
版本稳定性遵循语义化版本频繁发布破坏性变更
依赖链依赖少且都是知名库依赖繁重且多为小众库

Anti-Patterns

反模式

Anti-PatternWhy BadBetter
extern crate
Outdated (2018+)Just
use
#[macro_use]
Global pollutionExplicit import
Wildcard deps
*
UnpredictableSpecific versions
Too many depsSupply chain riskEvaluate necessity
Vendoring everythingMaintenance burdenTrust crates.io

反模式危害优化方案
extern crate
已过时(2018年起)直接使用
use
引入
#[macro_use]
全局污染显式导入宏
通配符依赖
*
版本不可预测指定具体版本
依赖过多供应链风险评估依赖必要性
手动 vendoring 所有依赖维护负担重信任crates.io上的库

Related Skills

相关技能

WhenSee
Error type designm06-error-handling
Trait integrationm04-zero-cost
FFI safetyunsafe-checker
Resource managementm12-lifecycle
适用场景参考内容
错误类型设计m06-error-handling
Trait集成m04-zero-cost
FFI安全性unsafe-checker
资源管理m12-lifecycle