I trying to create async fetch function, but it doesn't work. Also why I have to pass & pointer to client.get() function?
extern crate reqwest;
extern crate futures;
extern crate tokio;
use futures::Future;
use reqwest::r#async::{Client};
fn fetch(url: String) -> impl Future<Item=(), Error=()> {
let z = url;
Client::new()
.get(&z)
.send()
.and_then(|res| {
println!("{:?} {}", res.status(), url);
res
})
}
fn main() {
let url = format!("https://www.rust-lang.org/");
tokio::run(fetch(url));
println!("Done.");
Ok(())
}
errors:
error[E0277]: the trait bound `reqwest::async::Response: futures::Future` is not satisfied
--> src\main.rs:31:10
|
31 | .and_then(|res| {
| ^^^^^^^^ the trait `futures::Future` is not implemented for `reqwest::async::Response`
|
= note: required because of the requirements on the impl of `futures::IntoFuture` for `reqwest::async::Response`
error[E0271]: type mismatch resolving `<futures::AndThen<reqwest::async_impl::client::Pending, reqwest::async::Response, [closure@src\main.rs:31:19: 34:10 url:_]> as futures::Future>::Error == ()`
--> src\main.rs:26:26
|
26 | fn fetch(url: String) -> impl Future<Item=(), Error=()> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected struct `reqwest::Error`, found ()
|
= note: expected type `reqwest::Error`
found type `()`
= note: the return type of a