logoalt Hacker News

Functional State Machines in Rust: Typestate and Newtype Patterns

35 pointsby matt_dyesterday at 7:01 PM3 commentsview on HN

Comments

vatsachakyesterday at 10:41 PM

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

show 1 reply