This is my code. I'm trying to get posts from the Rust subreddit. I would be using Actix's built in client, but it's not working on Windows, hence the use of reqwest
instead:
use actix_web::{self, middleware, web, App, HttpRequest, HttpServer};
use futures::future::Future;
use reqwest::{
self,
r#async::{Client},
};
fn get_rust_posts(
_req: HttpRequest,
client: web::Data<Client>,
) -> impl Future<Item = String, Error = reqwest::Error> {
client
.get("http://www.reddit.com/r/rust.json")
.send()
.and_then(|mut resp| resp.text())
.map_err(|err| {
println!("Error in get rust posts: {}", err);
err
})
}
fn main() {
let mut server = HttpServer::new(|| {
App::new()
.data(Client::new())
.wrap(middleware::Logger::default())
.service(web::resource("/get/rust/posts").route(web::get().to_async(get_rust_posts)))
});
server.bind(("0.0.0.0", 8000)).unwrap().run().unwrap();
}
[dependencies]
actix-web = "1.0.8"
futures = "0.1.29"
reqwest = "0.9.21"
This is the error:
error[E0277]: the trait bound `fn(actix_web::request::HttpRequest, actix_web::data::Data<reqwest::async_impl::client::Client>) -> impl futures::future::Future
{get_rust_posts}: actix_web::handler::AsyncFactory<_, _>` is not satisfied
--> src\main.rs:29:72
|
29 | .service(web::resource("/get/rust/posts").route(web::get().to_async(get_rust_posts)))
| ^^^^^^^^ the trait `actix_web::handler::AsyncFactory<_, _>` is not implemented for
`fn(actix_web::request::HttpRequest, actix_web::data::Data<reqwest::async_impl::client::Client>) -> impl futures::future::Future {get_rust_posts}