pub trait Machine: Serialize + for<'de> Deserialize<'de> {
type State: Debug + Clone + Serialize + for<'de> Deserialize<'de>;
// Required method
fn current_state(&self) -> &Self::State;
// Provided methods
fn to_json(&self) -> Result<String, Error> { ... }
fn from_json(json: &str) -> Result<Self, Error>
where Self: Sized { ... }
}Expand description
The base trait for all Gust state machines.
Every machine generated by the Gust compiler implements Machine,
which provides state inspection and JSON round-trip serialization.
The trait requires Serialize and Deserialize so that machine
instances can be persisted, transferred, or logged as JSON.
§Associated types
State– the enum of possible states for this machine. Must beDebug + Clone + Serialize + Deserialize.
§Examples
ⓘ
use gust_runtime::prelude::*;
// Given a generated TrafficLight machine:
let light = TrafficLight::new();
println!("Current state: {:?}", light.current_state());
// Serialize to JSON for persistence
let json = light.to_json().unwrap();
// Restore from JSON
let restored = TrafficLight::from_json(&json).unwrap();Required Associated Types§
Required Methods§
Sourcefn current_state(&self) -> &Self::State
fn current_state(&self) -> &Self::State
Returns a reference to the machine’s current state.
Provided Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.