DDtKey / protect-endpoints

Authorization extension for popular web-frameworks to protect your endpoints
Apache License 2.0
203 stars 14 forks source link

Wrap proc-macroed function body in closure #4

Closed usbalbin closed 3 years ago

usbalbin commented 3 years ago

Description:

Make ?-operator and early returning work as expected in functions with the #[has_permissions("foo")] attribute. This simply wraps the function body in a closure with an async block whis is immediately called and awaited. I believe that probably makes this a breaking change?

It should probably be noted that I have never played with the implementation of proc macros before...

Checklist:

Closes #3

usbalbin commented 3 years ago

The tests are passing locally when changing

https://github.com/DDtKey/actix-web-grants/blob/6e64d8efddab695e37703fad786b3dd7ffbc9c87/Cargo.toml#L24 to

actix-grants-proc-macro = { path = "proc-macro", optional = true }

in order to depend on the local version of actix-grants-proc-macro, not sure what to do about that...

DDtKey commented 3 years ago

in order to depend on the local version of actix-grants-proc-macro, not sure what to do about that...

You can read a description of this problem in another PR.

It's easy to solve, you can just add path and leave the version:

actix-grants-proc-macro = { path = "./proc-macro", version = "1", optional = true }

I also have few comments about this approach to solving the problem with Result. I'll write them soon 🙂

usbalbin commented 3 years ago

Not sure if you want me to fix the rest of the cargo fmt-related errors

DDtKey commented 3 years ago

Not sure if you want me to fix the rest of the cargo fmt-related errors

Thanks for you contribution! 🚀 You did a great job, soon I will make a merge with minor changes and notify you. I want to add a test with move semantics 🙂

DDtKey commented 3 years ago

I merged the changes into #5. Thanks again!

usbalbin commented 3 years ago

Thank you for the awesome crate :)