pub trait ProtocolStateMachine:
Send
+ Sync
+ Debug {
// Required methods
fn state_name(&self) -> &str;
fn can_send(&self, msg_type: &str, from_role: &str) -> bool;
fn can_receive(&self, msg_type: &str, to_role: &str) -> bool;
fn transition(&mut self, msg_type: &str) -> Result<(), ProtocolViolation>;
fn is_terminal(&self) -> bool;
fn protocol_name(&self) -> &str;
fn clone_box(&self) -> Box<dyn ProtocolStateMachine>;
}Expand description
Trait for protocol state machines.
This trait is implemented by generated code for each protocol declaration. It tracks the current state and validates message transitions.
Required Methods§
Sourcefn state_name(&self) -> &str
fn state_name(&self) -> &str
Get the name of the current state.
Sourcefn can_send(&self, msg_type: &str, from_role: &str) -> bool
fn can_send(&self, msg_type: &str, from_role: &str) -> bool
Check if a message type can be sent from the given role in the current state.
Sourcefn can_receive(&self, msg_type: &str, to_role: &str) -> bool
fn can_receive(&self, msg_type: &str, to_role: &str) -> bool
Check if a message type can be received by the given role in the current state.
Sourcefn transition(&mut self, msg_type: &str) -> Result<(), ProtocolViolation>
fn transition(&mut self, msg_type: &str) -> Result<(), ProtocolViolation>
Transition the state machine based on a message.
§Errors
Returns a ProtocolViolation if the transition is invalid.
Sourcefn is_terminal(&self) -> bool
fn is_terminal(&self) -> bool
Check if the protocol has reached a terminal (accepting) state.
Sourcefn protocol_name(&self) -> &str
fn protocol_name(&self) -> &str
Get the protocol name.
Sourcefn clone_box(&self) -> Box<dyn ProtocolStateMachine>
fn clone_box(&self) -> Box<dyn ProtocolStateMachine>
Clone the state machine into a boxed trait object.