资源推荐
按学习阶段分类的 Rust 学习资源
标注 ★ 的为强烈推荐
一、书籍
入门阶段 (第 1-3 章)
书名 作者 推荐程度 链接 ★ The Rust Programming Language (TRPL) Steve Klabnik 必读 在线免费 Rust by Example Rust Team 配合TRPL 在线免费 Rustlings Rust Team 动手练习 GitHub
进阶阶段 (第 4-7 章)
书名 作者 推荐程度 说明 ★ Programming Rust (2nd) Blandy & Orendorff 深度理解 最好的 Rust 书, 有中文版 Rust for Rustaceans Jon Gjengset 进阶必读 讲解 Rust 的”为什么” The Rustonomicon Rust Team unsafe 专项 在线免费
专题书籍
书名 专题 推荐程度 ★ Rust Atomics and Locks 并发/内存模型 Mara Bos 著, 在线免费 Zero to Production in Rust Web 开发 Actix/Axum 生态 Rust in Action 系统编程 Tim McNamara 著 Learn Rust with Entirely Too Many Linked Lists unsafe + 数据结构 在线免费
二、官方文档
三、视频课程
课程 平台 内容 推荐程度 ★ Crust of Rust YouTube (Jon Gjengset) 深入单个特性 必看 Let’s Get Rusty YouTube 入门系列 好 Jon Gjengset 的直播录像 YouTube 实际项目编码 专家级 Tensor Programming YouTube 项目实战 好 中文: Rust 编程语言入门 Bilibili 中文入门 好
四、博客与文章
英文资源
中文资源
五、开源项目推荐
适合学习代码的项目
有趣的 Rust 项目
六、工具链
必备工具
# 安装 Rust
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
# 常用命令
rustup update # 更新工具链
rustup component add clippy rustfmt rust-analyzer
cargo new my_project # 创建项目
cargo build --release # 构建
cargo test # 测试
cargo clippy # Lint
cargo fmt # 格式化
cargo doc --open # 生成文档
cargo bench # 基准测试
推荐 cargo 扩展
工具 安装 用途 ★ cargo-watch cargo install cargo-watch文件变化自动重编译 cargo-expand cargo install cargo-expand宏展开查看 cargo-asm cargo install cargo-asm查看生成汇编 cargo-audit cargo install cargo-audit安全漏洞审计 cargo-outdated cargo install cargo-outdated检查依赖更新 cargo-llvm-lines cargo install cargo-llvm-lines分析编译时间 cargo-criterion cargo install cargo-criterion基准测试 flamegraph cargo install flamegraph性能火焰图 cargo-udeps cargo install cargo-udeps找无用依赖
IDE 配置
# VS Code (推荐)
扩展: rust-analyzer (必装)
扩展: Even Better TOML
扩展: CodeLLDB (调试)
扩展: crates (Cargo.toml 依赖提示)
# 设置 (settings.json)
{
"rust-analyzer.checkOnSave.command": "clippy",
"rust-analyzer.inlayHints.enable": true,
"editor.formatOnSave": true
}
七、社区与问答
八、速查表 (Cheat Sheet)
所有权速查
值绑定: let x = value; → x 拥有 value
移动: let y = x; → y 拥有, x 不可用 (非Copy)
复制: let y = x; → y 是副本, x 仍可用 (Copy类型)
借用: let r = &x; → r 借用 x, x 仍可用
可变借: let r = &mut x; → r 可变借用 x (独占)
克隆: let y = x.clone(); → 深复制, 两者独立
生命周期速查
// 函数
fn foo <' a >(x : & ' a str , y : & ' a str ) -> & ' a str { ... }
// 结构体
struct Foo <' a > {
x : & ' a str ,
}
// 方法
impl <' a > Foo <' a > {
fn method ( & ' a self ) -> & ' a str { ... }
}
// 'static
fn static_ref () -> & ' static str { "hello" } // 字符串字面量
错误处理速查
// 返回类型
fn foo () -> Result < T , E >
fn bar () -> Option < T >
// 传播错误
let x = foo () ? ; // 失败时提前返回
// 转换
result . unwrap () // panic on err
result . expect ( "msg" ) // panic with msg
result . unwrap_or (default) // 默认值
result . map ( | v | ... ) // 转换 Ok 值
result . and_then ( | v | ... ) // 链式 Result
Trait 速查
// 定义
trait Greet {
fn greet ( & self ) -> String ;
fn hello ( & self ) { println! ( "{}" , self . greet ()); } // 默认实现
}
// 泛型约束
fn print < T : Display + Debug >(val : T ) { ... }
fn print < T >(val : T ) where T : Display + Debug { ... }
// Trait 对象
fn do_stuff (val : &dyn Trait ) { ... } // 借用
fn do_stuff (val : Box < dyn Trait >) { ... } // 拥有
九、学习计划建议
最快路径 (8 周)
Week 1-2: TRPL 第1-10章 + Rustlings 前半
Week 3-4: 本教程 01-04 章 + 实战项目1 (minigrep)
Week 5-6: 本教程 05-07 章 + 实战项目2 (下载器)
Week 7-8: 本教程 08-10 章 + 面试准备
深度路径 (12 周)
Week 1-3: TRPL 全书 + Rustlings + cargo 工具熟悉
Week 4-6: Programming Rust + 本教程 01-05 章
Week 7-9: 本教程 06-10 章 + Rust for Rustaceans
Week 10-12: 实战项目3-4 + 开源贡献准备
十、常见依赖 Crate 推荐
[ dependencies ]
# 序列化/反序列化
serde = { version = "1" , features = [ "derive" ] }
serde_json = "1"
# 错误处理
thiserror = "1" # 库使用
anyhow = "1" # 应用程序使用
# 异步
tokio = { version = "1" , features = [ "full" ] }
# HTTP 客户端
reqwest = { version = "0.11" , features = [ "json" ] }
# CLI
clap = { version = "4" , features = [ "derive" ] }
# 日志
tracing = "0.1"
tracing-subscriber = "0.3"
# 时间
chrono = "0.4"
# 随机数
rand = "0.8"
# 并行
rayon = "1"
# 正则
regex = "1"
# UUID
uuid = { version = "1" , features = [ "v4" ] }
[ dev-dependencies ]
# 测试
criterion = { version = "0.5" , features = [ "html_reports" ] } # 基准测试
proptest = "1" # 属性测试
🦀 持续学习, 不断进步! Rust 社区欢迎你!