korken89 / smlang-rs

A State Machine Language DSL procedual macro for Rust
Apache License 2.0
192 stars 28 forks source link

Actions should consume data instead of using them as reference #48

Closed oblique closed 1 year ago

oblique commented 1 year ago

I want to move a non-clonable data from an event to the next state. This is currently not possible because data are passed as references in action's parameters.

An example of what I'm trying to do:

pub struct NonClonableData;

smlang::statemachine! {
    transitions: {
        *State1 + Event1(NonClonableData) / state1_event1_action = State2(NonClonableData),
        // ...
    }
}

struct Context;

impl StateMachineContext for Context {
    fn state1_event1_action(&mut self, event_data: NonClonableData) -> NonClonableData {
        event_data
    }
}

If you are willing to review and possibly merge a PR that passes the data as owned values, then I can implement this on my free time. This of-course will be a breaking change.