Skip to main content

ProtocolStateMachine

Trait ProtocolStateMachine 

Source
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§

Source

fn state_name(&self) -> &str

Get the name of the current state.

Source

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.

Source

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.

Source

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.

Source

fn is_terminal(&self) -> bool

Check if the protocol has reached a terminal (accepting) state.

Source

fn protocol_name(&self) -> &str

Get the protocol name.

Source

fn clone_box(&self) -> Box<dyn ProtocolStateMachine>

Clone the state machine into a boxed trait object.

Implementors§