rust_sfsm

Macro rust_sfsm 

Source
macro_rules! rust_sfsm {
    (
        $state_machine_name:ident {
            $($member_field:ident: $member_field_type:ty = $member_default:expr),* $(,)?
        },
        $state_type:ident,
        $event_type:ident,
        $context_type:ident
    ) => { ... };
    (
        $state_machine_name:ident,
        $state_type:ident,
        $event_type:ident,
        $context_type:ident
    ) => { ... };
    (
        @generate $state_machine_name:ident, $state_type:ident, $event_type:ident, $context_type:ident,
        members { $($member_field:ident: $member_field_type:ty = $member_default:expr),* }
    ) => { ... };
}
Expand description

§Rust Static FSM

A full static Rust finite state machine macro library.

§Usage

The rust_sfsm macro takes as input the state machine’s name, the states enum, the events enum and the context struct.

The state machine’s name can be just an ident if no other member is necessary to the struct:

use rust_sfsm::{rust_sfsm, StateBehavior};

#[derive(Clone, Copy, PartialEq)]
enum States {
    (...)
}

#[derive(Clone, Copy, PartialEq)]
enum Events {
    (...)
}

#[derive(Default)]
struct Context {
    (...)
}

rust_sfsm!(FooName, States, Events, Context);

The state machine’s name can also be a struct with default values if data other than the cotext is desired:

rust_sfsm!(
    FooName {
        foo_data: u16 = 0,
        boo_data: boo = false,
    },
    States,
    Events,
    Context
);