pub trait State:
Clone
+ PartialEq
+ Debug
+ Serialize
+ for<'de> Deserialize<'de>
+ Send
+ Sync {
// Required method
fn name(&self) -> &str;
// Provided methods
fn is_final(&self) -> bool { ... }
fn is_error(&self) -> bool { ... }
}Expand description
Trait for state machine states.
All methods are pure - no side effects. States represent immutable values that describe the current position in a state machine.
§Required Traits
Clone: States must be cloneable for history trackingPartialEq: States must be comparable for transition logicDebug: States must be debuggable for diagnosticsSerialize+Deserialize: States must be serializable for persistence
§Example
use mindset::core::State;
use serde::{Deserialize, Serialize};
#[derive(Clone, PartialEq, Debug, Serialize, Deserialize)]
enum TaskState {
Pending,
Running,
Complete,
Failed,
}
impl State for TaskState {
fn name(&self) -> &str {
match self {
Self::Pending => "Pending",
Self::Running => "Running",
Self::Complete => "Complete",
Self::Failed => "Failed",
}
}
fn is_final(&self) -> bool {
matches!(self, Self::Complete | Self::Failed)
}
fn is_error(&self) -> bool {
matches!(self, Self::Failed)
}
}Required Methods§
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.