Functional State Machines in Rust: Typestate and Newtype Patterns

dl.acm.org

26 points by matt_d 4 hours ago


vatsachak - 19 minutes ago

Types are puzzles. A good Rustacean will make sure that the pieces fit to make the picture.

That's why in crates where I need to make sure certain functions are called in order, I use a Ticket<T>, where one function returns a Ticket<Func1Done> with the output and the other has to consume it as an input.

The typestate pattern is a specialization of making only valid states representable

michaelnoguera - an hour ago

pdf: https://dl.acm.org/doi/pdf/10.1145/3830438.3830958