01

What Is This Thing?

A quick tour of Microsoft's open-source Rust training — seven books, seven on-ramps, one language.

The Big Picture

Imagine you want to learn Rust — a programming language that companies like Microsoft, Google, and Amazon use for their most demanding software. Where do you start?

If you search online, you will find hundreds of tutorials. Most of them assume you are starting from zero. But what if you already know Python, or C#, or C++? You do not need someone to explain what a variable is — you need someone to explain how Rust thinks differently from the language you already know.

That is exactly what Microsoft built. The RustTraining project is a collection of seven free training books, each designed for people coming from different programming backgrounds. Think of it like a music school with different departments: every department teaches the same instrument, but a guitarist learns differently from a pianist, even though they are both learning drums.

Three of the books are called Bridge books — they connect what you already know to Rust:

C
Rust for C/C++ Programmers

Ownership as an upgrade from manual memory management. If you think in pointers and malloc, this book speaks your language.

C#
Rust for C# Programmers

From garbage collection to ownership. Maps familiar .NET patterns — LINQ, async/await, generics — to their Rust equivalents.

Py
Rust for Python Programmers

From dynamic typing to static guarantees. Shows how Rust replaces duck typing with traits, and why that is a feature, not a limitation.

The Learning Paths

Beyond the three Bridge books, the project offers four more books that go deeper into specific areas of Rust. Here is the full lineup:

C
Rust for C/C++ Programmers

Bridge — 16 chapters mapping systems-level concepts to Rust's ownership model.

C#
Rust for C# Programmers

Bridge — 15 chapters connecting .NET patterns to Rust idioms.

Py
Rust for Python Programmers

Bridge — 15 chapters translating dynamic Python thinking into static Rust thinking.

~
Async Rust

Deep Dive — futures, Tokio, streams, and cancellation safety in 15 chapters.

P
Rust Patterns

Advanced — design patterns, idiomatic APIs, and architectural best practices.

T
Type-Driven Correctness

Expert — encoding business rules in the type system so invalid states are unrepresentable.

E
Rust Engineering Practices

Practices — CI/CD, testing strategies, project structure, and team workflows.

💡
Key Insight

This project inverts traditional education. Instead of "learn everything, then build," it meets you where you are. Each Bridge book assumes you are already a competent programmer — it just shows you how Rust does things differently from the language you already think in.

What Makes These Books Special

These are not ordinary PDFs or blog posts. Every book is built with mdbook, a tool that turns plain Markdown files into interactive websites. Here are the four features that make them stand out:

1
Mermaid diagrams that visualize complex concepts

Ownership graphs, async state machines, type hierarchies — all rendered as clean diagrams right inside the chapter, generated from simple text descriptions.

2
Editable Rust playgrounds (run code in the browser)

Every code example is editable. Change a line, click Run, and see the output instantly — no local Rust installation needed.

3
Exercises at the end of each chapter

Each chapter ends with hands-on exercises that reinforce the concepts you just learned, giving you a chance to practice before moving on.

4
Full-text search across all chapters

Need to find where traits are discussed? The built-in search indexes every chapter, so you can jump directly to the concept you need.

Here is how the playground feature is configured. This snippet comes from the book.toml file — the configuration file that controls how each book is built:

book.toml [output.html.playground] editable = true line-numbers = true
Plain English
[output.html.playground] — This section controls the code examples on the website
editable = true — Let readers change the code and run it — like a mini coding sandbox
line-numbers = true — Show line numbers next to code so readers can follow along easily

Check Your Understanding

1. A colleague who writes Python wants to learn Rust. Which book would you recommend they start with?
2. Your team wants to evaluate Rust's async programming model. Which book focuses on that?
3. What makes these training books different from a typical programming tutorial?
02

Meet the Cast

The actors, stage crew, and director behind the scenes

The Cast of Characters

Every codebase has characters — pieces of software that each play a specific role. Let's meet the stars of this show.

📖
mdbook

The engine that transforms plain Markdown text files into beautiful, searchable book websites

🔧
xtask

The stage manager. A custom Rust program that orchestrates building all 7 books and serves them locally

🐳
Docker

The shipping container. Packages everything into a portable box that runs anywhere

🤖
GitHub Actions

The automation robot. Deploys the books to the web whenever code changes (CI/CD)

The Directory Map

Let's look at how the files are organized.

RustTraining/
c-cpp-book/ Rust for C/C++ Programmers
src/ Chapter content (Markdown files)
book.toml Book configuration
csharp-book/ Rust for C# Programmers
python-book/ Rust for Python Programmers
async-book/ Async Rust deep dive
rust-patterns-book/ Advanced patterns
type-driven-correctness-book/ Expert type techniques
engineering-book/ Engineering practices
xtask/ The build orchestrator
src/main.rs All build logic lives here
docker/ Container configuration
Dockerfile Multi-stage build recipe
nginx.conf Web server settings
.github/workflows/ CI/CD automation
Cargo.toml Rust workspace configuration

How They Work Together

When you run cargo xtask serve, here is what happens behind the scenes:

The Workspace Glue

The root Cargo.toml ties the whole project together. Let's read it line by line.

CODE
[workspace]
resolver = "2"
members = ["xtask"]
PLAIN ENGLISH

This file defines a workspace — a way to group related Rust projects together under one roof

Use the modern dependency resolution strategy (version 2 is smarter about avoiding conflicts). The resolver handles all of that automatically.

The only actual Rust program in this workspace is xtask — the build tool that manages everything

💡
Key Insight

The 7 books aren't Rust programs — they're Markdown text files. The only actual code is the xtask build tool that transforms them into websites.

Check Your Understanding

You want to change how code examples look in the books. Which actor handles that transformation?

You notice the landing page (the page listing all 7 books) looks broken. Where would you look to fix it?

What is the relationship between the 7 book folders and the xtask folder?

03

The Build Pipeline

How plain text becomes a beautiful website

From Text to Website

You have met the cast. Now let us watch them perform. When someone types cargo xtask build, a chain reaction begins.

Think of it like a printing press: raw manuscripts (Markdown files) go in, beautifully typeset books (HTML websites) come out. The press operator (xtask) feeds each manuscript through the press (mdbook) one by one, then arranges them all in a bookshop window (the landing page).

📝
Developer
🔧
xtask
📖
mdbook
🌐
Website
Click "Next Step" to begin

The Book Registry

How does xtask know which books to build? It uses a hardcoded constant called BOOKS — a list of every book in the project. Each entry stores four pieces of information: the folder name (slug), the human-readable title, a short description, and a category.

Here is what the first entry looks like:

xtask/src/main.rs const BOOKS: &[(&str, &str, &str, &str)] = &[ ( "c-cpp-book", "Rust for C/C++ Programmers", "Move semantics, RAII, FFI, embedded, no_std", "bridge", ),
Plain English
const BOOKS: &[(&str, &str, &str, &str)] = &[ — Create a permanent list called BOOKS. Each entry has 4 text fields: slug, title, description, and category
"c-cpp-book", — The folder name where this book lives on disk
"Rust for C/C++ Programmers", — The human-readable title shown on the landing page
"Move semantics, RAII, FFI, embedded, no_std", — A short description of what the book covers
"bridge", — The category — this is a bridge book (teaches Rust from another language)

The Build Loop

Once xtask knows about every book, it loops through them one by one. For each book, it runs mdbook as an external Command — the same way you would type mdbook build in your terminal, but automated.

xtask/src/main.rs for &(slug, _, _, _) in BOOKS { let book_dir = root.join(slug); let dest = out.join(slug); let status = Command::new("mdbook") .args(["build", "--dest-dir"]) .arg(&dest) .current_dir(&book_dir) .status() .expect("failed to run mdbook");
Plain English
for &(slug, _, _, _) in BOOKS { — Go through each book one by one. We only need the folder name (slug) — ignore the rest for now
let book_dir = root.join(slug); — Find the book folder on disk (e.g., /RustTraining/c-cpp-book/)
let dest = out.join(slug); — Decide where to put the finished website (e.g., site/c-cpp-book/)
let status = Command::new("mdbook") — Run the mdbook program — like typing a command in the terminal
.args(["build", "--dest-dir"]) — Tell mdbook: build this book and put the output in a specific folder
.arg(&dest) — Here is that specific folder
.current_dir(&book_dir) — Run from inside the book folder so mdbook finds the right files
.expect("failed to run mdbook"); — If mdbook crashes, stop everything and show this error message

The Custom Web Server

After building the books, you need a way to preview them locally. Most projects reach for an existing tool — but xtask includes its own built-in HTTP server.

💡
Why build a custom server?

Most projects use existing tools like python -m http.server. But the xtask team built their own to add security features — like blocking hackers from reading files outside the website folder.

The custom server includes three layers of defense against path traversal attacks:

🛡️
Path Traversal Protection

Blocks attempts to access files outside the site/ folder using tricks like ../../../etc/passwd

🚫
Null Byte Rejection

Rejects requests containing null bytes — a classic hacking technique that tricks programs into misreading file paths

🔒
Symlink Escape Prevention

Verifies that the final file path is actually inside the site folder, even if symlinks try to redirect elsewhere

Check Your Understanding

1. The build process fails on the async-book but succeeds for all other books. What is the MOST likely cause?
2. You want to add an 8th book called "Rust for Go Programmers." What do you need to do?
3. Why does the built-in web server check file paths so carefully?
04

From Code to Cloud

How the books travel from source code to your browser

The Two Deployment Paths

The books are built. Now how do they reach readers? This project has two paths to the web — one automated, one containerized.

🚀
GitHub Pages

Free, automatic. Every push to the main branch triggers a workflow that builds and publishes the books. Zero server maintenance.

🐳
Docker + nginx

Self-hosted. Package everything into a container and run it anywhere — your own server, a cloud provider, behind a corporate firewall.

The GitHub Actions Workflow

When a developer pushes code to the main branch, a fully automated pipeline takes over. GitHub Actions orchestrates every step — no human intervention required.

1

Code is pushed to the main branch

2

GitHub Actions checks out the code and installs Rust

3

It caches dependencies so builds are faster next time

4

It installs mdbook and mdbook-mermaid

5

It runs cargo xtask deploy (same build process, outputs to docs/)

6

GitHub Pages publishes docs/ as a live website

💡
Key Insight

The deployment uses the exact same xtask tool as local development. The only difference is the output folder: site/ for local preview, docs/ for GitHub Pages. Same code, different destination.

The Docker Recipe

The second deployment path uses Docker to package the books into a self-contained unit. The key technique is a multi-stage build — one stage builds the books, and a second, much smaller stage serves them.

Dockerfile FROM rust:1-slim-bookworm AS builder RUN cargo install mdbook mdbook-mermaid COPY . /src WORKDIR /src RUN cargo xtask build FROM nginxinc/nginx-unprivileged:1.27-alpine COPY --from=builder /src/site/ /usr/share/nginx/html/ EXPOSE 8080
Plain English
FROM rust:1-slim-bookworm AS builder — Start with a pre-made box that has Rust installed. Call this stage 'builder' — it will be thrown away later
RUN cargo install mdbook mdbook-mermaid — Install the book-building tools inside the box
COPY . /src — Copy all the book source files into the box
WORKDIR /src — Move into the source directory
RUN cargo xtask build — Build all 7 books into HTML — the same command developers run locally
FROM nginxinc/nginx-unprivileged:1.27-alpine — Start a NEW, tiny box with only a web server. The builder box (with Rust, compilers, etc.) is discarded
COPY --from=builder /src/site/ /usr/share/nginx/html/ — Grab just the finished websites from the builder box and place them where nginx can serve them
EXPOSE 8080 — Tell Docker this container listens on port 8080 for web traffic

Why Two Stages?

ℹ️
Multi-Stage Builds

The builder stage includes Rust, cargo, mdbook, and all compilation tools — over 1 GB of software. The final stage is just nginx + static HTML files — under 50 MB. Multi-stage builds keep the final image small and secure by throwing away everything that was only needed for building.

The final nginx stage is not just small — it is also hardened for production. Here are the three key security and performance features baked into the configuration:

🔐
Security Headers

X-Content-Type-Options, X-Frame-Options, and Referrer-Policy headers protect against common web attacks

👤
Unprivileged User

The container runs as a non-root user (uid 101) — even if someone breaks in, they cannot harm the system

⚡
Asset Caching

Static files are cached for 1 day, with gzip compression for CSS, JS, and SVG — faster page loads for readers

Check Your Understanding

1. The Docker image is 2 GB in size, making deployments slow. What would you investigate first?
2. A new team member pushes code to a feature branch, but the books do not update on the website. Why?
3. Your company wants to host the training books behind a corporate firewall with no internet access. Which deployment path would you use?
05

The Teaching Toolkit

The interactive tools that make learning stick

More Than Just Text

Most programming tutorials are walls of text with occasional code blocks. These books pack interactive tools into every chapter.

📊
Mermaid Diagrams

Visualize complex flows — like how async code executes or how data moves between components. Written as text, rendered as beautiful SVGs.

▶️
Editable Playgrounds

Code examples you can edit and run directly in the browser. Change a variable, hit Run, see what happens. No setup required.

🎯
Difficulty Indicators

Every chapter is tagged with difficulty: green for easy, yellow for intermediate, red for hard. You always know what you are getting into.

🔍
Full-Text Search

Search across all chapters in a book instantly. Forgot where ownership was explained? Search and jump right there.

How Diagrams Are Born

The books use Mermaid to create diagrams. Instead of drawing in an image editor, you write plain text — and a preprocessor converts it into a clean SVG diagram during the build. Here is a real example from the async book showing how futures are polled:

async-book ch02 — Mermaid diagram sequenceDiagram participant E as Executor participant F as Future (Task) participant OS as Operating System participant R as Reactor (Runtime) E->>F: Calls poll(cx) F->>OS: Syscall (e.g., read TCP socket) OS-->>F: Returns Error: Not Ready F-->>E: Returns Poll::Pending
Plain English
sequenceDiagram — Draw a timeline showing messages flowing between actors, from top to bottom
participant E as Executor — Create an actor called "Executor" (the thing that runs tasks) — label it "E" for short
participant F as Future (Task) — Create an actor called "Future" — a task that will eventually produce a result
participant OS as Operating System — The operating system — the software that manages your computer hardware
participant R as Reactor (Runtime) — The reactor — a listener that watches for events (like data arriving from the network)
E->>F: Calls poll(cx) — Solid arrow from Executor to Future: "Hey, are you done yet?"
F->>OS: Syscall — Future asks the operating system to check the network socket
OS-->>F: Returns Error: Not Ready — Dashed arrow back: "Nope, no data yet"
F-->>E: Returns Poll::Pending — Future tells Executor: "Not ready — I will let you know when I am"

The Book Configuration

Every book in the project has a book.toml file — a TOML configuration that tells mdbook how to build it. Here is a simplified version from the async book:

book.toml [book] title = "Async Rust" authors = ["Rust Training Team"] language = "en" [preprocessor.mermaid] command = "mdbook-mermaid" [output.html] default-theme = "light" preferred-dark-theme = "ayu"
Plain English
[book] — Basic book information — title, authors, and language
title = "Async Rust" — The name shown in the browser tab and page header
authors = ["Rust Training Team"] — Who wrote it — shown in the book metadata
language = "en" — Written in English — affects things like search behavior and text direction
[preprocessor.mermaid] — Before building, run the Mermaid preprocessor to convert diagram text into images
command = "mdbook-mermaid" — The actual program to run for Mermaid processing
[output.html] — Settings for the HTML output
default-theme = "light" — Start with a light background (readers can switch to dark mode)
preferred-dark-theme = "ayu" — When readers choose dark mode, use the "Ayu" color scheme — a popular warm-toned dark theme

The Curriculum Architecture

Each book follows a consistent three-part structure. This is not random — it mirrors how experts actually learn: start with what you know, go deep on the hard parts, then prove you can build something real.

1
Part I: Foundations

The basics, connecting Rust concepts to what you already know

2
Part II: Deep Dives

Focused exploration of major topics (concurrency, async, systems)

3
Part III: Practice

Best practices, migration guides, and a capstone project to tie it all together

💡
Key Insight

Every bridge book ends with a capstone project — a real, complete application. The C# book builds a CLI weather tool. The Python book builds a task manager. You do not just learn concepts — you build something real.

The Big Picture

Let us zoom out and see how everything fits together. The entire system has three layers: content goes in, the build system transforms it, and the delivery layer gets it to readers.

Content Layer
📚 7 Book Folders
📝 Markdown + Mermaid
Build Layer
🔧 xtask
📖 mdbook
Delivery Layer
🤖 GitHub Actions
🐳 Docker + nginx
Click any component to learn what it does

Check Your Understanding

1. You want to add a diagram showing how Rust ownership works to the C# book. What do you need to do?
2. A reader reports that code examples in the Python book cannot be edited or run. What is the most likely configuration issue?
3. Your company wants to create a similar training system for Go. Based on what you learned, what would be your recommended first step?