</>PatchNote
Back to posts

2024-07-06

HSPACE Rust Lectures #0 — Getting Started

RustHSPACE 2024Linux Kernel

In the summer of 2024 I took the Rust Basic + Linux Kernel lecture series at HSPACE, taught by Chris Ohk. The slides, examples, and assignments live in my 2024-HSPACE-Rust-LinuxKernel repository.

Starting with this post, I'm writing one entry per session. These are not transcriptions of the slides — they're closer to "what confused me and how I eventually made sense of it."

The books

The lectures don't follow one book verbatim, but these were the main references.

Book
PrimaryProgramming Rust (O'Reilly Media, 2021)
Comprehensive Rust (Google, 2023)
The Rust Programming Language, 2nd Edition (No Starch Press, 2023)
SecondaryThe Rustonomicon
Rust for Rustaceans (No Starch Press, 2021)
Rust Atomics and Locks (O'Reilly Media, 2023)
Effective Rust (O'Reilly Media, 2024)

In practice the session order tracks Programming Rust almost chapter for chapter: fundamental types → ownership and moves → references → expressions → error handling → crates and modules → closures → concurrency → macros → async. Whenever a slide lost me, opening that chapter was the fastest way out.

How the sessions run

  • Twice a week, one topic per day: theory slides → example code → (some weeks) an assignment.
  • Assignments are mostly "make cargo test pass". The tests act as the spec, so there's never any ambiguity about what you're supposed to build.
  • Example code lives under 2 - Example, assignments under 3 - Assignment, and solutions under 4 - Solution in the repository.

The series is named Rust Basic + Linux Kernel, but the sessions that actually ran covered the language itself. The kernel and device-driver material sits on top of that foundation, so these notes follow the Rust track in order.

Rust Playground

Before installing anything, the first thing I played with was the Rust Playground. It compiles and runs in the browser, and more importantly it lets you choose what form of output you want to see:

  • Run — just run it
  • Build — build only
  • ASM / LLVM IR / MIR / HIR — the intermediate representation at each stage

Being able to look at ASM and MIR mattered more than I expected. Later sessions repeatedly claim "this abstraction costs nothing at runtime," and here you can verify that by reading the assembly instead of taking it on faith. Every time I wondered whether a closure or an iterator really does get inlined away, I came back to this page.

Install and project setup

Locally, rustup handles the toolchain.

# Linux/macOS
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

# check
rustc --version
cargo --version

For the editor I used VS Code with rust-analyzer. Its inlay type hints help a lot early on, because Rust lets you omit types in so many places that you're constantly asking "wait, what type is this variable right now?"

Every project goes through cargo.

cargo new hello          # binary project (src/main.rs)
cargo new mylib --lib    # library project (src/lib.rs)

cargo build              # debug build   → target/debug
cargo build --release    # release build → target/release
cargo run                # build and run
cargo test               # run tests

--release turns on optimization at the cost of build time and debug info. The gap shows up dramatically when measuring multithreaded performance in the concurrency session, which is where I picked up the habit of checking "is this a release build?" before believing any timing number.

Next

Next up is the first real session — the key features of Rust: ownership, borrowing and lifetimes, traits, Option/Result, and what exactly the language means when it calls itself safe.