Tokio::run(fetch()); type mismatch resolving `<impl futures::Future as futures::Future>::Item == ()`


Hi ,

I (rust beginner) was exploring example . Which returns empty future . What I want to do is return future with some value but I am getting

error[E0271]: type mismatch resolving `<impl futures::Future as futures::Future>::Item == ()`
  --> src/
35 |     tokio::run(fetch());
   |     ^^^^^^^^^^ expected struct `Test`, found ()
   = note: expected type `Test`
              found type `()`
   = note: required by `tokio::run`

error: aborting due to previous error


extern crate futures;
extern crate gcm;
extern crate http;
extern crate reqwest;
extern crate tokio;

use std::mem;

use futures::{Future, Stream};
use futures::future::ok;
use reqwest::async::{Chunk, Client, Decoder};

struct Test{

fn fetch() -> impl Future<Item=Test, Error=()> {

        .and_then(|mut res| {
            println!("{}", res.status());

            let body = mem::replace(res.body_mut(), Decoder::empty());
        .map_err(|err| ())
        .and_then(|ch| Ok(Test{count:1}))


fn main() {

Tokio expects a future that returns (). So your function return type should be

impl Future<Item=(), Error=()>
1 Like

See also


let mut runtime = tokio::runtime::Runtime::new().expect("Unable to create a runtime");
let s = runtime.block_on(example());
println!("{:?}", s);