Skip to content

Make state definition clearer #62

@hanekoo

Description

@hanekoo

If local storage is not used, the state_machine macro could generate the following State enum, which would make the usage more straightforward and clear:

pub enum State { LedOn, NotBlinking { b }, LedOff }

impl State {
    fn led_on() -> Self { Self::LedOn } // no local storage
    fn not_blinking(b) -> Self { Self::NotBlinking { b } } // with local storage
    fn led_off() -> Self { Self::LedOff }
}

Call Handler :

match self {
    State::LedOn => Blinky::led_on(event), // no local storage
    State::NotBlinking { b } => Blinky::not_blinking(b, event), // Uses local storage
    State::LedOff => Blinky::led_off(event),
    _ => statig::Response::Super
}

Get State :

match state_machine.state() {
    State::LedOn => {} // no local storage or extra parameters
    State::NotBlinking { b } => {}
    State::LedOff => {}
}

This approach would enhance clarity and improve the developer experience by making state transitions and handling more intuitive.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions