Functional State Machines in Rust: Typestate and Newtype Patterns

6 points by anex9d


fanf

abstract bypass dogshit pdf viewer

dilawar

Abstract: (notes in () are mine)

We investigate the effects on code quality of the design patterns typestate and newtype in the language Rust, by conducting three case studies... The findings indicate that: (1) Typestate improves code faultlessness and testability, but comes at the cost of more boilerplate code and can degrade readability (use macros?). Code with extensive branching logic and many invariants likely benefits most from the pattern. (2) Newtype combined with the “Parse, don’t validate” principle improves code quality at a low cost and prevents invalid states at runtime.