Macro rotor::rotor_compose [] [src]

macro_rules! rotor_compose {
    (pub enum $name:ident/$cname:ident <$context_type:ident>
        { $($x:ident ($y:ty),)* }) => { ... };
    (enum $name:ident/$cname:ident <$context_type:ident>
        { $($x:ident ($y:ty),)* }) => { ... };
    (@machine $name:ident/$cname:ident $ctx_typ:ident
        [ $(<$ctx_name:ident $(: $ctx_bound:ident)*>)* ]
        $($iname:ident ($itype:ty),)*) => { ... };
}

Compose multiple state machines into single type

Composition requires two types: the state machine itself and Seed which is used to create children state machines.

Mostly because of limitations of Rust macro system composition only works on concrete context type.

Example

rotor_compose!{
    pub enum Fsm/Seed<Context> {
        Http(HttpMachine)
        Dns(DnsMachine)
    }
}Run

This creates a an Fsm state machine type which is enum with two options. And Seed state machine type, which is also enum with same option names but uses <HttpMachine as rotor::Machine>::Seed for the wrapped type.