IO Type problems. expected struct `reqwest::Error`, found ()

#1

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
#2

Hi, welcome!

.send() returns an error, but you’ve said you don’t want any errors (Error=()). Add .map_err(|_| ()) to the chain to throw away the error value.

#3

it doesn’t help, I still get same error, where do I have to put it?

    error[E0271]: type mismatch resolving `<futures::MapErr<reqwest::async_impl::client::Pending, [closure@src\main.rs:31:18: 31:24]> as futures::Future>::Item == ()`
  --> src\main.rs:26:26
   |
    26 | fn fetch(url: String) -> impl Future<Item=(), Error=()> {
           |                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected struct `reqwest::async::Response`, found ()
           |
           = note: expected type `reqwest::async::Response`
                      found type `()`
           = note: the return type of a function must have a statically known size
#4

Well, you’re one step ahead.

impl Future<Item=(), Error=()> means no result, and no error. () is Rust’s type for nothing.

.and_then(|res| {
            println!("{:?} {}", res.status(), url);
            res
        })

returns res. Delete res and you’ll get no result, as you asked in the function signature. Or, update function signature to allow it to return the Item=reqwest::async::Response