# Crate 与依赖管理

URL: https://caijiao.org/rust/09-ecosystem/01-crates
Source: docs/rust/09-ecosystem/01-crates.md
Description: Rust 使用 Crate 和 Cargo 管理依赖，支持模块化开发和版本控制，极大地提升了包的复用性与维护性。

在 Rust 中，**Crate** 是包和模块的最小单元，而 **Cargo** 是官方的构建工具和依赖管理器。一个项目通常包含一个或多个 crate，并通过 `Cargo.toml` 来管理依赖关系。

## 常用命令

```bash
cargo new my_project       # 创建新项目
cargo build                # 构建项目
cargo run                  # 编译并运行
cargo add serde            # 添加依赖（需要 cargo-edit）
```

## Cargo.toml 示例

```toml
[dependencies]
serde = "1.0"
tokio = { version = "1.0", features = ["full"] }
```

## 代码演示

Rust Playground 示例代码
