Skip to content

State Definition Flexibility #43

@christianheussy

Description

@christianheussy

Current Limitation

Currently, the macro does not support user-defined state enums. This limitation is particularly noticeable when users require fine-grained control over Serde serialization/deserialization, specifically when needing to leverage attributes like skip and default. Workarounds involve either manual implementation or forgoing the macro entirely, which can be cumbersome and less efficient.

Proposed Solution

Introduce a "Bring Your Own State" (BYOS) mechanism. This will allow users to define their own custom State enum by adding a custom_state option to the state attribute within the macro. The macro should enforce that the name item within the state attribute matches the variant names defined in the custom State enum.

struct Foo;

MyState {
    On,
    Off
}

#[state_machine(state(custom_state, name = "MyState"))]
impl Foo {
    #[state(name = "On")]
    fn on() -> Response<MyState> {
        todo!()
    }
    
    #[state(name = "Off")]
    fn on() -> Response<MyState> {
        todo!()
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions