I'm creating an application to get data from an API. Then I used reqwest. Main.rs file has server configuration. Then I created route.rs file to manage every methods. And I created separated files to each function.
route.rs
use crate::search::User;
use actix_web::{get, post, put, delete, web, HttpResponse, Responder};
use serde_json::json;
extern crate reqwest;
extern crate serde;
mod common;
#[get("/token")]
async fn get_token() -> String {
let set_token = common::authenticate();
return set_token;
}
For the first error, it's really a bit more complicated. The problem is in the error message: since we're dealing with async function, it should be read inversely - "expected Result (due to return value), got String (which is really being returned)".
error[E0277]: the trait bound `search::routes::reqwest::Error: search::routes::serde::Serialize` is not satisfied
--> src\search\routes.rs:24:29
|
24 | HttpResponse::Ok().json(set_token)
| ^^^^^^^^^ the trait `search::routes::serde::Serialize` is not implemented for `search::routes::reqwest::Error`
|
= note: required because of the requirements on the impl of `search::routes::serde::Serialize` for `std::result::Result<(), search::routes::reqwest::Error>`
error[E0308]: mismatched types
--> src\search\routes\common.rs:27:14
|
27 | .headers(construct_headers())
| ^^^^^^^^^^^^^^^^^^^ expected struct `search::routes::reqwest::header::HeaderMap`, found struct `hyper::header::Headers`
|
= note: expected struct `search::routes::reqwest::header::HeaderMap`
found struct `hyper::header::Headers`
error[E0308]: mismatched types
--> src\search\routes\common.rs:34:8
|
34 | Ok(reszr)
| ^^^^^ expected `()`, found struct `std::string::String`
For 27 you have a HeaderMap, but you need to convert it into a Headers. I'm not quite sure what the best way to do that is, but you should probably look at the documentation of the two mentioned types.
For 34 it appears that you're trying to return a String, but that's not the right return type.
You are mixing the hyper and reqwest crates with the headers. Please change your code to use HeaderMap instead. As for the reszr error, it's because you need to return Ok(reszr).