Here is a paired down version of my code
#[post("/api/v1.0/account/auth")]
pub fn account_auth(req: HttpRequest, input: web::Json<AuthRequest>) -> Result<web::Json<AuthResponse>, web::Json<ForwardError>> {
Ok(web::Json(AuthResponse{
token: "eyy".to_string(),
expires: 60
}))
}
Here's the error:
error[E0277]: the trait bound `fn(actix_web::request::HttpRequest, actix_web::data::Data<core::structs::GlobalState>, actix_web::types::json::Json<account::session::AuthRequest>) -> std::result::Result<actix_web::types::json::Json<account::session::AuthResponse>, actix_web::types::json::Json<core::structs::ForwardError>> {<account::session::account_auth as actix_web::service::HttpServiceFactory>::register::account_auth}: actix_web::handler::Factory<_, _>` is not satisfied
--> src/account/session.rs:24:1
|
24 | #[post("/api/v1.0/account/auth")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `actix_web::handler::Factory<_, _>` is not implemented for `fn(actix_web::request::HttpRequest, actix_web::data::Data<core::structs::GlobalState>, actix_web::types::json::Json<account::session::AuthRequest>) -> std::result::Result<actix_web::types::json::Json<account::session::AuthResponse>, actix_web::types::json::Json<core::structs::ForwardError>> {<account::session::account_auth as actix_web::service::HttpServiceFactory>::register::account_auth}`
Running under Rust Nightly using actix-web 1.0.3. I tried this with the same function in the docs as well with the same result. It looks like there is an issue with the Macro or I shouldn't be using a Macro for this.
Does it work without macro? Does AuthRequest implements Serialize trait?
i ran into this same issue. it seems like the issue is using something other than actix_web::Error for the second parameter. i was refactoring some code to return a custom error enum and replaced impl Future<Item = HttpResponse, Error = Error> with impl Future<Item = HttpResponse, Error = ErrorKind>.
not sure if that is intended, but the compiler message is vv cryptic
In case anyone gets here and the previous suggestions don't work - my mistake was to forget the async keyword on my handler function 馃う You definitely need it! Or else I guess construct the equivalent type signature in terms of futures or whatever.
can someone clarify how can that be done/fixed with an closure ?
Most helpful comment
In case anyone gets here and the previous suggestions don't work - my mistake was to forget the
asynckeyword on my handler function 馃う You definitely need it! Or else I guess construct the equivalent type signature in terms of futures or whatever.