typestate-rs
typestate-rs copied to clipboard
Feature request: "Missing initial state" error when using `Self`
When I had this trait for transitions relating to my Opened
state everything worked as expected with the new
function making Opened
the start state.
pub trait Opened {
fn new() -> Opened;
// ...
}
However, changing the return value for new
from Opened
to Self
causes the macro to abort with several errors, beginning with:
error: Missing initial state. To declare an initial state you can use a function with signature like
fn f() -> T
whereT
is a declared state.
It would be nicer, I think, if I could use -> Self
because it helps make the initial state stand out.
Hello! Thank you for submitting this issue!
The fix should be simple enough. However, the part of the code that handles that needs a bit of refactoring.
The following function and friends should have more context on the current state: https://github.com/rustype/typestate-rs/blob/ad6c9022f5dc001424ec59f2cea585328d38a740/typestate-proc-macro/src/visitors/transition.rs#L295-L312
If the function knows which state is it part of, it can return the correct ident