The trait bound `reqwest::error::Error: _IMPL_DESERIALIZE_FOR_User::_serde::Serialize` is not satisfied

Hi all,

I'm new to Rust and am having a tough time trying to decipher this error message:
the trait bound reqwest::error::Error: _IMPL_DESERIALIZE_FOR_User::_serde::Serialize is not satisfied.

For context, the first function get_canvas_self below works correctly, but I'm not sure how to write the second function canvas_self (which is an endpoint for returning the result of the call to get_canvas_self).

async fn get_canvas_self() -> Result<User, Error> {
    dotenv().ok();

    let base_url = env::var("CANVAS_API_DOMAIN").expect("Canvas API Domain not set in .env");
    let token = env::var("CANVAS_API_TOKEN").expect("Canvas Token not set in .env");
    let endpoint = "/users/self";

    let client = reqwest::Client::new();
    let response = client
        .get(&format!("{}{}", base_url, endpoint))
        .header("Authorization", &format!("Bearer {}", token))
        .send()
        .await?
        .json::<User>()
        .await?;

    Ok(response)
}

#[get("/canvas_self")]
async fn canvas_self() -> Result<HttpResponse, Error> {
    let self_response = get_canvas_self().await;
    Ok(HttpResponse::Ok().json(self_response))
}

The full error is:

error[E0277]: the trait bound `reqwest::error::Error: _IMPL_DESERIALIZE_FOR_User::_serde::Serialize` is not satisfied
  --> src/main.rs:41:32
   |
41 |     Ok(HttpResponse::Ok().json(self_response))
   |                                ^^^^^^^^^^^^^ the trait `_IMPL_DESERIALIZE_FOR_User::_serde::Serialize` is not implemented for `reqwest::error::Error`
   |
   = note: required because of the requirements on the impl of `_IMPL_DESERIALIZE_FOR_User::_serde::Serialize` for `std::result::Result<User, reqwest::error::Error>

Thanks for your help!

1 Like

HttpResponse::Ok().json(self_response) is trying to serialize a value self_response whose type is Result<User, reqwest::error::Error>, but reqwest::error::Error is not serializable.

I'm guessing you wanted to serialize just the User i.e. if self_response is Ok.

1 Like

Thanks @dtolnay!

I fixed this error by adding ? to let self_response = get_canvas_self().await?;, but now am facing a new error:

error[E0277]: the trait bound `fn() -> impl std::future::Future {<canvas_self as actix_web::service::HttpServiceFactory>::register::canvas_self}: actix_web::handler::Factory<_, _, _>` is not satisfied
  --> src/main.rs:39:10
   |
39 | async fn canvas_self() -> Result<HttpResponse, Error> {
   |          ^^^^^^^^^^^ the trait `actix_web::handler::Factory<_, _, _>` is not implemented for `fn() -> impl std::future::Future {<canvas_self as actix_web::service::HttpServiceFactory>::register::canvas_self}`

Any idea how I can resolve this?

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.