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

Model proc-macro WIP example #74

Open
DevinR528 opened this issue Mar 21, 2020 · 3 comments
Open

Model proc-macro WIP example #74

DevinR528 opened this issue Mar 21, 2020 · 3 comments

Comments

@DevinR528
Copy link
Contributor

One of the more interesting features of rust are proc-macro's, I have wondered if it was possible to use a diesel style "schema" generator to create the Model and by doing so create a type that can hold policy lines and have this also used in enforce possibly? This example is more a proof of concept to start a conversation about this feature.

I created a repo with a minimal-ish example
Casbin-proc-macro

Questions

Is it even wanted?
How would this be integrated without breaking existing code or have a simple upgrade path ?
Any other thoughts

Advantages

  • gives type safety to the model definition compile time errors, instead of runtime
  • by reading in the model we can dynamically define the Policy struct and the function to compare a request to a policy
  • no rhai this is maybe a positive not sure about the trade offs
  • maybe others?
@PsiACE
Copy link
Contributor

PsiACE commented Mar 23, 2020

Hi, I saw your work and it was great. Just wondering, what do you think is the necessity of this approach at this stage?

Since you mentioned diesel, I have some other ideas. For example

  • A configuration file like casbin.toml;
  • Some mechanisms like migrations.
  • Of course, the schema you mentioned is also an important part.

@DevinR528
Copy link
Contributor Author

what do you think is the necessity of this approach at this stage?

It would move a lot of code from runtime to being compile time checked. Removing the rhai eval would improve performance considerably. It isn't a necessity but it would be nice, as everything works now. I do think using something like the casbin-proc-macro example would allow for easy migrations and Model schema generation.

@GopherJ
Copy link
Member

GopherJ commented Apr 18, 2020

@DevinR528 I think some day we really need a modeling language for casbin so that things can be verified and validated and converted to the correct format.

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

3 participants