UPDATE: Use Type-State pattern without the ugly code (state-shift)

166 points ozgunozerk

If you haven’t heard about state-shift, here is the old post: https://www.reddit.com/r/rust/comments/1fqstm8/use\_typestate\_pattern\_without\_the\_ugly\_code

And here is the readme: https://github.com/ozgunozerk/state-shift/blob/main/README.md

When I released the first version, it was more of an MVP.

With amazing feedback and contributions from the community (that’s you there, hi!), the library is now much more refined, stable and feature-full.

Here are the biggest changes since the beginning:

  • generics, lifetimes, and visibility of the structs and methods are preserved (thanks to Johannes Kneer)
  • using full path for PhantomData instead of importing it (thanks to Sean P. Kelly)
  • Instead of having PhantomData<T> in the hidden _state field, we now have PhantomData<fn() -> State>. This makes is less strict for our struct to implement Send + Sync. (thanks to Veetaha -author of bon-)

Long story short, v1.0.0 is out 🚀

Feel free to use it and find even more bugs 🐞

And as always, everyone is welcome submit an issue or PR for anything.

GitHub link of the repo: https://github.com/ozgunozerk/state-shift

Thanks everyone! This community helped me so much in my Rust journey,
trying my best to return the favor 🦀