# Ana Hobden - Pretty State Machine Patterns in Rust (Highlights)

## Metadata
**Review**:: [readwise.io](https://readwise.io/bookreview/50704015)
**Source**:: #from/readwise #from/reader
**Zettel**:: #zettel/fleeting
**Status**:: #x
**Authors**:: [[Ana Hobden]]
**Full Title**:: Pretty State Machine Patterns in Rust
**Category**:: #articles #readwise/articles
**Category Icon**:: 📰
**Document Tags**:: #programming #rust
**URL**:: [hoverbear.org](https://hoverbear.org/blog/rust-state-machine-pattern/)
**Host**:: [[hoverbear.org]]
**Highlighted**:: [[2025-04-20]]
**Created**:: [[2025-04-23]]
## Highlights
- So here we're actually building the state into the type signature of the `BottleFillingMachine` itself. A state machine in the 'Filling' state is `BottleFillingMachine<Filling>` which is just **awesome** since it means when we see it as part of an error message or something we know immediately what state the machine is in. ([View Highlight](https://read.readwise.io/read/01js8wa8htw0yqv103x1zznftx)) ^879703656
↩︎
```
struct BottleFillingMachine<S> {
shared_value: usize,
state: S
}
```
- So how can we have some parent structure hold our state machine without it being a gigantic pain to interact with? Well, this circles us back around to the `enum` idea we had at first. ([View Highlight](https://read.readwise.io/read/01js8wdv0w0etq1fhj6f9gjwz8)) ^879703785