Skip to main content

FsmState

Trait FsmState 

Source
pub trait FsmState:
    Send
    + Sync
    + 'static {
    // Required methods
    fn as_key(&self) -> String;
    fn from_key(key: &str) -> Option<Self>
       where Self: Sized;
}
Expand description

A type that can be used as an FSM state.

Implement this trait on an enum to use it with StateContext and the FSM dispatcher.

In practice you will derive this via #[derive(FsmState)]:

#[derive(Clone, Debug, PartialEq)]
enum CheckoutState {
    Cart,
    Address,
    Payment,
    Confirmation,
}

Required Methods§

Source

fn as_key(&self) -> String

Serialize this state variant to a string key (e.g. "WaitingProduct").

Source

fn from_key(key: &str) -> Option<Self>
where Self: Sized,

Deserialize a state variant from a key string. Returns None if the key does not match any variant.

Implementors§