πŸ¦€/πŸ”¬/Introduction

Type-Driven Correctness in Rust

Speaker Intro

  • Principal Firmware Architect in Microsoft SCHIE (Silicon and Cloud Hardware Infrastructure Engineering) team
  • Industry veteran with expertise in security, systems programming (firmware, operating systems, hypervisors), CPU and platform architecture, and C++ systems
  • Started programming in Rust in 2017 (@AWS EC2), and have been in love with the language ever since

A practical guide to using Rust's type system to make entire classes of bugs impossible to compile. While the companion Rust Patterns book covers the mechanics (traits, associated types, type-state), this guide shows how to apply those mechanics to real-world domains β€” hardware diagnostics, cryptography, protocol validation, and embedded systems.

Every pattern here follows one principle: push invariants from runtime checks into the type system so the compiler enforces them.

How to Use This Book

Difficulty Legend

SymbolLevelAudience
🟒IntroductoryComfortable with ownership + traits
🟑IntermediateFamiliar with generics + associated types
πŸ”΄AdvancedReady for type-state, phantom types, and session types

Pacing Guide

GoalPathTime
Quick overviewch01, ch13 (reference card)30 min
IPMI / BMC developerch02, ch05, ch07, ch10, ch172.5 hrs
GPU / PCIe developerch02, ch06, ch09, ch10, ch152.5 hrs
Redfish implementerch02, ch05, ch07, ch08, ch17, ch183 hrs
Framework / infrastructurech04, ch08, ch11, ch14, ch182.5 hrs
New to correct-by-constructionch01 β†’ ch10 in order, then ch12 exercises4 hrs
Full deep diveAll chapters sequentially7 hrs

Annotated Table of Contents

ChTitleDifficultyKey Idea
1The Philosophy β€” Why Types Beat Tests🟒Three levels of correctness; types as compiler-checked guarantees
2Typed Command Interfaces🟑Associated types bind request β†’ response
3Single-Use Types🟑Move semantics as linear types for crypto
4Capability Tokens🟑Zero-sized proof-of-authority tokens
5Protocol State MachinesπŸ”΄Type-state for IPMI sessions + PCIe LTSSM
6Dimensional Analysis🟒Newtype wrappers prevent unit mix-ups
7Validated Boundaries🟑Parse once at the edge, carry proof in types
8Capability Mixins🟑Ingredient traits + blanket impls
9Phantom Types🟑PhantomData for register width, DMA direction
10Putting It All Together🟑All 7 patterns in one diagnostic platform
11Fourteen Tricks from the Trenches🟑Sentinelβ†’Option, sealed traits, builders, etc.
12Exercises🟑Six capstone problems with solutions
13Reference Cardβ€”Pattern catalogue + decision flowchart
14Testing Type-Level Guarantees🟑trybuild, proptest, cargo-show-asm
15Const Fn🟠Compile-time proofs for memory maps, registers, bitfields
16Send & Sync🟠Compile-time concurrency proofs
17Redfish Client Walkthrough🟑Eight patterns composed into a type-safe Redfish client
18Redfish Server Walkthrough🟑Builder type-state, source tokens, health rollup, mixins

Prerequisites

ConceptWhere to learn it
Ownership and borrowingRust Patterns, ch01
Traits and associated typesRust Patterns, ch02
Newtypes and type-stateRust Patterns, ch03
PhantomDataRust Patterns, ch04
Generics and trait boundsRust Patterns, ch01

The Correct-by-Construction Spectrum

← Less Safe                                                    More Safe β†’

Runtime checks      Unit tests        Property tests      Correct by Construction
─────────────       ──────────        ──────────────      ──────────────────────

if temp > 100 {     #[test]           proptest! {         struct Celsius(f64);
  panic!("too       fn test_temp() {    |t in 0..200| {   // Can't confuse with Rpm
  hot");              assert!(          assert!(...)       // at the type level
}                     check(42));     }
                    }                 }
                                                          Invalid program?
Invalid program?    Invalid program?  Invalid program?    Won't compile.
Crashes in prod.    Fails in CI.      Fails in CI         Never exists.
                                      (probabilistic).

This guide operates at the rightmost position β€” where bugs don't exist because the type system cannot express them.