3 comments

  • vatsachak 1 hour 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

    • LtdJorge 39 minutes ago
      One of my favorite useful patterns
  • arpinum 16 minutes ago
    I use Typestates and Newtypes extensively. The metric that shows Typestate and Newtypes are beneficial is: How many method calls or parameters can be called / used that compile but are not valid use cases. You want to minimise this number. I love having a type state where I can only make 1 or 2 method calls because the state enforces there are only a few parsing / validation / transition methods available. And there is only one valid way to supply the parameters, I cannot use the strings in the wrong location. I only wish we had named parameters like ObjC.
  • michaelnoguera 2 hours ago