DDtKey / protect-endpoints

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

?-operator and `proc-macro`-method #3

Closed usbalbin closed 3 years ago

usbalbin commented 3 years ago

Hi!

I have been trying this for my own project and I have to say it is very convenient. However I am noticing that functions with lots of calls that can fail are a bit awkward to write since the ?-operator does not work.

#[get("/foo")]
#[has_permissions("foo")]
pub async fn foo() -> Result<HttpResponse, SomeError> {
    let a = thing_that_might_fail().await?;  //<-- Error: ? can only be used in a function that returns Result or...
    let b = other_thing(a).await?;           //<-- Error
    let c = yet_other_thing(b).await?;       //<-- Error
    Ok(and_so_on(c).await)
}

Do you have any suggestions for how I should write a similar function? Or might I request some way of supporting the ?-operator :)

DDtKey commented 3 years ago

It's a good point! Indeed, at the moment there is a bug with Result when used in conjunction with a macro. We should support this case in the actix-web-grants crate.

Thanks for issue and your PR 👍