Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/badboy/microstate
Finite state machine, inspired by micromachine
https://github.com/badboy/microstate
Last synced: 9 days ago
JSON representation
Finite state machine, inspired by micromachine
- Host: GitHub
- URL: https://github.com/badboy/microstate
- Owner: badboy
- License: mit
- Created: 2015-06-13T10:46:54.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2016-07-27T06:09:58.000Z (over 8 years ago)
- Last Synced: 2024-12-24T02:01:28.996Z (12 days ago)
- Language: Rust
- Homepage: http://badboy.github.io/microstate/
- Size: 540 KB
- Stars: 26
- Watchers: 3
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
MicroState
=========[![Build Status](https://travis-ci.org/badboy/microstate.svg?branch=master)](https://travis-ci.org/badboy/microstate)
[![crates.io](http://meritbadge.herokuapp.com/microstate)](https://crates.io/crates/microstate)Minimal Finite State Machine.
Description
-----------A finite state machine is in only one state at a time.
From there it can change from one state to another when initiated by an triggering event: the transition.
A finite state machine is fully defined by a list of states and the transitions triggering a change from one state to another.And that's all this crate does: it lets you define the states and transitions.
The rest is up to you.Inspired by [@soveran](https://twitter.com/soveran)'s [micromachine](https://github.com/soveran/micromachine) in Ruby.
Documentation
-------------[Online documentation](http://badboy.github.io/microstate/microstate)
Usage
-----First you need to import the macro:
```rust
#[macro_use] extern crate microstate;
```You can then create a new state machine and call transitions.
```rust
microstate!{
MicroMachine { New };
states { New, Confirmed, Ignored };confirm {
New => Confirmed
}ignore {
New => Ignored
}reset {
Confirmed => New
Ignored => New
}
}let mut machine = MicroMachine::new();
machine.confirm(); // => Some(Confirmed)
machine.state(); // => Confirmedmachine.ignore(); // => None
machine.state(); // => Confirmedmachine.reset(); // => Some(New)
machine.state(); // => Newmachine.ignore(); // => Some(Ignored)
machine.state(); // => Ignored
```## Contribute
If you find bugs or want to help otherwise, please [open an issue](https://github.com/badboy/microstate/issues).
## License
MIT. See [LICENSE](LICENSE).