Actix-web: the trait `actix_web::handler::Factory<_, _>` is not implemented

Created on 6 Jul 2019  路  4Comments  路  Source: actix/actix-web

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.

Most helpful comment

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.

All 4 comments

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 ?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

yoshrc picture yoshrc  路  5Comments

gh67uyyghj picture gh67uyyghj  路  3Comments

mcelkys picture mcelkys  路  4Comments

zhaobingss picture zhaobingss  路  4Comments

cheolgyu picture cheolgyu  路  3Comments