Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] Allow pre-declaring the enumerate type's output for Derive usage #37

Open
Dessix opened this issue Jul 9, 2022 · 2 comments

Comments

@Dessix
Copy link

Dessix commented Jul 9, 2022

It would be helpful if the enum produced by typestate(enumerate = ...) could be pre-declared such that #[derive(...)] can be used upon it or potentially (a subset of?) its members.

#[typestate(enumerate = "StateMachineStates")
pub mod state_machine {
  #[automaton]
  #[derive(Debug, Clone, PartialEq, Eq)]
  pub struct StateMachine;

  #[state] pub struct In;
  #[state] pub struct Out;

  // No field-specific annotations
  #[enumerate]
  #[derive(Debug, Clone, PartialEq, Eq)]
  pub enum StateMachineStates;

  // or, with fields annotated for another annotation-macro
  #[enumerate]
  #[derive(derivative)]
  #[derivative(Debug)]
  pub enum StateMachineStates {
    #[derivative(Debug="transparent")]
    In,
    // Note that only some states are included
    // Any not explicitly mentioned are filled in prior to other #[derive]s expanding.
  }

  // ...
}
@jmg-duarte
Copy link
Contributor

Hey @Dessix! Thank you for your interest!

This crate has been in a weird state since this was my MSc's thesis PoC and I haven't had time since to work on it. Only recently I have started to think about ways to make it simpler both the DSL and the macro powering it.

That said, I can't make any promises. If you have any more ideas or suggestions, feel free to share them in the discussions or issues!

@Dessix
Copy link
Author

Dessix commented Jul 11, 2022

Thanks! I'm hoping to make use of this for its self-documenting features to more-strictly encode various protocols in one of my projects, and have been mulling over a helper annotation for creating the trait impls without all of the verbosity and boilerplate. Ideally, the proc-macro annotation would handle this so it could utilize the contextual information from the main mod body.

I think one of the big parts of making an effective DSL is keeping it from getting in the way of the language's features- the relevant one here being derive. Feel free to bounce ideas off of me if you're not sure of a particular syntactical direction to take, or how to implement some aspect of the macro processing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants