State Definition Flexibility
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!()
}
}
This ticket is a good excuse for me to become more familiar with the macro. I'll take a stab at it.
Resolved by #49
Woot!