Trait StateMachine

Source
pub trait StateMachine {
    type Output;
    type Msg;

    // Required methods
    fn proceed(&mut self) -> ProceedResult<Self::Output, Self::Msg>;
    fn received_msg(
        &mut self,
        msg: Incoming<Self::Msg>,
    ) -> Result<(), Incoming<Self::Msg>>;
}
Available on crate feature state-machine only.
Expand description

Provides interface to execute the protocol

Required Associated Types§

Source

type Output

Output of the protocol

Source

type Msg

Message of the protocol

Required Methods§

Source

fn proceed(&mut self) -> ProceedResult<Self::Output, Self::Msg>

Resumes protocol execution

Returns ProceedResult which will indicate, for instance, if the protocol wants to send or receive a message, or if it’s finished.

Calling proceed after protocol has finished (after it returned ProceedResult::Output) returns an error.

Source

fn received_msg( &mut self, msg: Incoming<Self::Msg>, ) -> Result<(), Incoming<Self::Msg>>

Saves received message to be picked up by the state machine on the next proceed invocation

This method should only be called if state machine returned ProceedResult::NeedsOneMoreMessage on previous invocation of proceed method. Calling this method when state machine did not request it may return error.

Calling this method must be followed up by calling proceed. Do not invoke this method more than once in a row, even if you have available messages received from other parties. Instead, you should call this method, then call proceed, and only if it returned ProceedResult::NeedsOneMoreMessage you can call received_msg again.

Implementors§