Rust 教程
面向已具备编程基础的读者,顺序为工具链与所有权 → 类型与模式 → trait 与错误处理 → 集合与并发 → 测试与 unsafe 边界。示例以 当前 Stable 与 2021 Edition 为默认语境(Cargo.toml 中 edition = "2021")。
章节
| 章节 | 内容 |
|---|---|
| 安装与 Cargo | rustup、工作区、Cargo.toml/Cargo.lock |
| 所有权、借用与生命周期 | 移动、引用规则、NLL、生命周期省略 |
| 类型、切片与字符串 | 标量与复合类型、切片、String/str、UTF-8 |
| 结构体、枚举与模式 | struct、enum、match、穷尽性 |
| Trait 与泛型 | trait、dyn Trait、关联类型、where 约束 |
| 错误处理 | Result、?、thiserror/anyhow 角色 |
| 集合与迭代器 | Vec、HashMap、迭代器与 collect |
| 并发 | Send/Sync、Arc、Mutex、消息传递 |
| 测试 | cargo test、集成测试目录、#[cfg(test)] |
| unsafe 与 FFI | unsafe 语义、FFI 与 repr 纪律 |