A reference application written in Rust language providing a pattern for a database-backed finite state machine.
Create a reference application that is usable as the programmatic model for an on-line service, supporting concurrent execution and stateless, horizontally scaling.
A simple life model to illustrate a state machine: a life that is either gestating, alive, or dead.
into
by implementing From on variants' typesstate_type
: the textual name of the parent variant's type; used to construct model from database resultcreated_at
, updated_at
, born_at
, died_at
+---------------------------------+ +-----------------------------+ +----------------------------+
| | | | | |
| enum variant Phase::Gestating | | enum variant Phase::Alive | | enum variant Phase::Dead |
| | | | | |
| +-----------------------------+ | | +-------------------------+ | | +------------------------+ |
| | | | | | | | | | | |
+-----+ Gestating +------------------->Alive | +---------------->Dead <---------+
| | | | | into | | | | into | | | | |
| | | state: Life (database record) | | | state: Life (database record) | | state: Life (database record) |
| | | state_type: "Gestating"| | | state_type: "Alive"| | | state_type: "Dead"| |
| | | born_at: none | | | | born_at: some time | | | born_at: some time| |
| | | ... | | | | ... | | | | ... | | |
| | | | | | | | | | | | | |
| | | | | | | | | | | | | |
| | +-----------------------------+ | | +-------------------------+ | | +------------------------+ | |
| +---------------------------------+ +-----------------------------+ +----------------------------+ |
| |
| |
+------------------------------------------------------------------------------------------------------------------------------------+
into
cargo install diesel_cli --no-default-features --features postgres
cp .env.sample .env
diesel setup
Now, build & test the program:
cargo test