Functional State Machines in Rust: Typestate and Newtype Patterns
summary
Three production Rust case studies (detail-view service, JSON tag handler, AWS return-status lambda) use static metrics, four expert interviews and Criterion microbenchmarks to measure effects of typestate and newtype patterns. Results: newtype + parse-don't-validate consistently reduces runtime-invalid inputs and improves testability with little boilerplate; typestate makes illegal operation sequences unrepresentable (uses typestate consumes self transitions), increasing faultlessness for branching logic but adding scaffolding and mixed analyzability impacts. Benchmarks show no measurable latency cost (±2% threshold).
AI-written summary · about
chapters (10)
- 0:00Introduction
- 5:46Rust adoption motivation
- 9:00Typestate and newtype patterns
- 13:18Study design and criteria
- 17:14Detail view service refactor
- 17:55Tag component handler refactor
- 21:35Return status cloud function refactor
- 25:49Results and feedback
- 30:24Recommendations and future
- 31:49Q&A
related talks
31mThe Rust That Could Have Been
26mThe Freedom of Static Typing
25mType System Tips for the Real World
44mTyped Design Patterns for the Functional Era
25m"Compiler-Driven Development: Making Rust Work for You"
19mType Theory for the Working Rustacean
46mKeynote: Rust is not about memory safety
43mLow-level optimization of algebraic and similar structures
