casbin / casbin-rs

An authorization library that supports access control models like ACL, RBAC, ABAC in Rust.
https://casbin.org
Apache License 2.0
832 stars 67 forks source link

Model proc-macro WIP example #74

Open DevinR528 opened 4 years ago

DevinR528 commented 4 years ago

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

PsiACE commented 4 years ago

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

DevinR528 commented 4 years ago

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 commented 4 years ago

@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.