Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Rust Bootstrap Course for C/C++ Programmers / 面向 C/C++ 程序员的 Rust 入门强化课程

Course Overview / 课程概览

  • Course overview / 课程包含以下内容
    • The case for Rust (from both C and C++ perspectives) / 为什么选择 Rust(从 C 和 C++ 两个角度出发)
    • Local installation / 本地安装
    • Types, functions, control flow, pattern matching / 类型、函数、控制流、模式匹配
    • Modules, cargo / 模块与 Cargo
    • Traits, generics / Trait 与泛型
    • Collections, error handling / 集合与错误处理
    • Closures, memory management, lifetimes, smart pointers / 闭包、内存管理、生命周期、智能指针
    • Concurrency / 并发
    • Unsafe Rust, including Foreign Function Interface (FFI) / Unsafe Rust,包括外部函数接口(FFI)
    • no_std and embedded Rust essentials for firmware teams / 面向固件团队的 no_std 与嵌入式 Rust 核心内容
    • Case studies: real-world C++ to Rust translation patterns / 案例研究:真实世界中的 C++ 到 Rust 迁移模式
  • We’ll not cover async Rust in this course - see the companion Async Rust Training for a full treatment of futures, executors, Pin, tokio, and production async patterns
  • 本课程讲解 async Rust;如需系统学习 futures、执行器、Pin、tokio 与生产级异步模式,请参考配套的 Async Rust Training

Self-Study Guide / 自学指南

This material works both as an instructor-led course and for self-study. If you’re working through it on your own, here’s how to get the most out of it:

本材料既适合讲师授课,也适合自学。如果你打算独立学习,下面的建议可以帮助你获得更好的学习效果:

Pacing recommendations / 学习节奏建议:

Chapters / 章节Topic / 主题Suggested Time / 建议时间Checkpoint / 检查点
1-4Setup, types, control flow / 环境、类型、控制流1 day / 1 天You can write a CLI temperature converter / 你可以写出一个命令行温度转换器
5-7Data structures, ownership / 数据结构、所有权1-2 days / 1-2 天You can explain why let s2 = s1 invalidates s1 / 你可以解释为什么 let s2 = s1 会使 s1 失效
8-9Modules, error handling / 模块、错误处理1 day / 1 天You can create a multi-file project that propagates errors with ? / 你可以创建一个多文件项目并用 ? 传播错误
10-12Traits, generics, closures / Trait、泛型、闭包1-2 days / 1-2 天You can write a generic function with trait bounds / 你可以写出带 trait 约束的泛型函数
13-14Concurrency, unsafe/FFI / 并发、unsafe/FFI1 day / 1 天You can write a thread-safe counter with Arc<Mutex<T>> / 你可以用 Arc<Mutex<T>> 写出线程安全计数器
15-16Deep dives / 深入专题At your own pace / 自定节奏Reference material - read when relevant / 作为参考材料,在需要时查阅
17-19Best practices & reference / 最佳实践与参考At your own pace / 自定节奏Consult as you write real code / 在实际写代码时按需查阅

How to use the exercises / 如何使用练习:

  • Every chapter has hands-on exercises marked with difficulty: 🟢 Starter, 🟡 Intermediate, 🔶 Challenge / 每章都包含带难度标记的动手练习:🟢 入门、🟡 中级、🔶 挑战
  • Always try the exercise before expanding the solution. Struggling with the borrow checker is part of learning - the compiler’s error messages are your teacher / 总是先做题,再看答案。 与借用检查器“拉扯”是学习的一部分,编译器的报错就是你的老师
  • If you’re stuck for more than 15 minutes, expand the solution, study it, then close it and try again from scratch / 如果卡住超过 15 分钟,就先看答案、理解思路,再关闭答案重新独立完成
  • The Rust Playground lets you run code without a local install / Rust Playground 允许你无需本地安装就运行代码

When you hit a wall / 遇到难点时:

  • Read the compiler error message carefully - Rust’s errors are exceptionally helpful / 仔细阅读编译器错误信息,Rust 的错误提示通常非常有帮助
  • Re-read the relevant section; concepts like ownership (ch7) often click on the second pass / 重读相关章节,像所有权这类概念常常在第二遍时真正理解
  • The Rust standard library docs are excellent - search for any type or method / Rust 标准库文档 非常优秀,任何类型或方法都值得查阅
  • For async patterns, see the companion Async Rust Training / 如需学习异步模式,请参考配套的 Async Rust Training

Table of Contents / 目录

Part I - Foundations / 第一部分:基础

1. Introduction and Motivation / 1. 引言与动机

2. Getting Started / 2. 快速开始

3. Basic Types and Variables / 3. 基础类型与变量

4. Control Flow / 4. 控制流

5. Data Structures and Collections / 5. 数据结构与集合

6. Pattern Matching and Enums / 6. 模式匹配与枚举

7. Ownership and Memory Management / 7. 所有权与内存管理

8. Modules and Crates / 8. 模块与 Crate

9. Error Handling / 9. 错误处理

10. Traits and Generics / 10. Trait 与泛型

11. Type System Advanced Features / 11. 类型系统高级特性

12. Functional Programming / 12. 函数式编程

13. Concurrency / 13. 并发

14. Unsafe Rust and FFI / 14. Unsafe Rust 与 FFI

Part II - Deep Dives / 第二部分:深入专题

15. no_std - Rust for Bare Metal / 15. no_std:面向裸机的 Rust

16. Case Studies: Real-World C++ to Rust Translation / 16. 案例研究:真实世界中的 C++ 到 Rust 迁移

Part III - Best Practices & Reference / 第三部分:最佳实践与参考

17. Best Practices / 17. 最佳实践

18. C++ to Rust Semantic Deep Dives / 18. C++ 到 Rust 的语义深入对比

19. Rust Macros / 19. Rust 宏