# 💋 SM – a static State Machine library
SM allows you to define a collection of states and events using Rust's type
system. Undefined behavior is not an option.
The implementation ensures a zero-sized abstraction that uses Rust's type-system
and ownership model to guarantee valid transitions between states using events,
and makes sure previous states are no longer usable after transitioning away to
another state, unless transitioned back to using any pre-defined state
transitions. Rust validates correct usage of the state machine at compile-time,
no runtime checking occurs when using the library.
The library exposes two traits, `State`, and `Event`, but primarily provides the
macro `sm!`, which allows you to declaratively build the state machine.
## Example
```rust
let stile = sm!{
TurnStile { Locked }
states { Locked, Unlocked }
coin {
Locked => Unlocked
Unlocked => Unlocked
}
push {
Locked => Locked
Unlocked => Locked
}
};
stile.state() // => Locked
let new_stile = stile.event(Invalid); // won't compile
let new_stile = stile.event(Coin); // => TurnStile<Unlocked>
stile.state() // won't compile
new_stile.state() // => Unlocked
```