-
Book Overview & Buying
-
Table Of Contents
Design Patterns and Best Practices in Rust
By :
In this chapter, we explored four patterns that leverage Rust's type system, each with established origins in programming language research and practice.
The NewType pattern comes from functional programming languages, particularly Haskell, where it has been a formal language feature since the 1990s. Rust's contribution is making the pattern zero-cost: type safety is enforced at compile time and optimized away entirely at runtime, making it practical for systems programming, where performance matters.
Parse, don't validate was articulated by Alexis King in 2019, building on ideas from functional programming and type theory. Rust's type system, ownership model, and Result type make this principle natural to apply, turning boundary validation into type-level guarantees that persist throughout the program.
The TypeState pattern originated in formal methods research, specifically in Strom and Yemini's 1986 work on program verification. Rust...