typestate-rs
typestate-rs copied to clipboard
Error when using non-C like enums inside a `#[typestate]` block
I ran across three related issues when reproducing this issue.
Take the following:
#[typestate]
mod my_state {
#[automaton]
struct Aut;
#[state]
struct State1(HelperEnum);
trait State1 {
fn new() -> State1;
fn done(self);
}
enum HelperEnum {}
}
The above produces the following error:
Unused transitions are not allowed.
After this, I tried changing the enum to be:
enum HelperEnum {
Variant1,
Variant2,
}
And got:
`enum` variant is not a declared state.
And finally, once I got to what I was trying to do (algebraic enums), by doing the following:
enum HelperEnum {
Variant1 { helper_state: bool },
Variant2,
}
}
I got the following error:
Only unit (C-like) `enum` variants are supported.
My current workaround is to declare the HelperEnum
just outside the module and use it from there. This makes code a bit disjoint, but it's doable. If this is intended behavior, it might be a good idea to add a note to the docs about it :)
I forgot to mention, but the reason I think this might be intentional behavior is because it appears to be an internal mechanism for keeping track of transitions or generating the graphs, but that's just my guess.
Sorry for the (very) late reply. "Normal" enumerations are disallowed inside the module as regular enumerations are used for decision-states. Support for them could be added through the usage of #[state]
but I don't know if that won't bring more complexity to the existing codebase for little benefit