[][src]Macro statemachine_macro::statemachine_new

statemachine_new!() { /* proc-macro */ }

Creates a statemachine.

Because statemachines do some magic processing to the underlying struct, regular struct literals do not work. By wrapping your struct literals in statemachine_new!, you can circumvent this restriction.

Note that you can alternatively derive Default for your statemachine struct.

Examples

Without statemachine_new!:

This example deliberately fails to compile
use statemachine_macro::*;

statemachine! {
    struct Foo {
        bar: i32
    }

    enum FooState consumes [char] from Start;
}

let _foo = Foo { bar: 3 };

With statemachine_new!:

use statemachine_macro::*;

statemachine! {
    struct Foo {
        bar: i32
    }

    enum FooState consumes [char] from Start;
}

let _foo = statemachine_new!(Foo { bar: 3 });

By deriving Default:

use statemachine_macro::*;

statemachine! {
    #[derive(Default)]
    struct Foo {
        bar: i32
    }

    enum FooState consumes [char] from Start;
}

let _foo: Foo = Foo { bar: 3, ..Default::default() };
let _baz: Foo = Default::default();