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
Rust 面向 C/C++ 程序员入门训练营

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:
学习节奏建议:

ChaptersTopicSuggested TimeCheckpoint
1–4
第 1–4 章
Setup, types, control flow
环境准备、类型与控制流
1 day
1 天
You can write a CLI temperature converter
能够写出一个命令行温度转换器。
5–7
第 5–7 章
Data structures, ownership
数据结构与所有权
1–2 days
1–2 天
You can explain why let s2 = s1 invalidates s1
能够说明 为什么 let s2 = s1 会让 s1 失效。
8–9
第 8–9 章
Modules, error handling
模块与错误处理
1 day
1 天
You can create a multi-file project that propagates errors with ?
能够写出一个多文件项目,并用 ? 传播错误。
10–12
第 10–12 章
Traits, generics, closures
Trait、泛型与闭包
1–2 days
1–2 天
You can write a generic function with trait bounds
能够写出带 trait 约束的泛型函数。
13–14
第 13–14 章
Concurrency, unsafe/FFI
并发与 unsafe/FFI
1 day
1 天
You can write a thread-safe counter with Arc<Mutex<T>>
能够用 Arc<Mutex<T>> 写出线程安全计数器。
15–16
第 15–16 章
Deep dives
专题深入
At your own pace
按个人节奏推进
Reference material — read when relevant
这部分更偏参考材料,遇到相关问题时回来看。
17–19
第 17–19 章
Best 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 模式上,继续看配套的 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++ → Rust Semantic Deep Dives
18. C++ → Rust 语义深入对照

19. Rust Macros
19. Rust 宏