Skip to content

Should Client (and its Futures) implement Send? #1082

Closed
@antoyo

Description

@antoyo

Hello.
I want to rewrite the http example of my library to use hyper since it is now based on tokio.

Here is my attempt at doing so.

It does not compile. I get the following error:

error[E0277]: the trait bound `futures::Future<Error=hyper::Error, Item=hyper::client::Response> + 'static: std::marker::Send` is not satisfied
   --> examples/http.rs:131:24
    |
131 |                 return connect(http_future, NewGif, &self.stream);
    |                        ^^^^^^^ the trait `std::marker::Send` is not implemented for `futures::Future<Error=hyper::Error, Item=hyper::client::Response> + 'static`
    |
    = note: `futures::Future<Error=hyper::Error, Item=hyper::client::Response> + 'static` cannot be sent between threads safely
    = note: required because of the requirements on the impl of `std::marker::Send` for `std::ptr::Unique<futures::Future<Error=hyper::Error, Item=hyper::client::Response> + 'static>`
    = note: required because it appears within the type `std::boxed::Box<futures::Future<Error=hyper::Error, Item=hyper::client::Response> + 'static>`
    = note: required because it appears within the type `hyper::client::FutureResponse`
    = note: required because it appears within the type `futures::MapErr<hyper::client::FutureResponse, [closure@examples/http.rs:158:29: 158:35]>`
    = note: required because it appears within the type `futures::future::chain::Chain<futures::MapErr<hyper::client::FutureResponse, [closure@examples/http.rs:158:29: 158:35]>, futures::stream::Fold<futures::stream::MapErr<hyper::Body, [closure@examples/http.rs:159:28: 159:34]>, [closure@examples/http.rs:159:49: 162:10], std::result::Result<std::vec::Vec<u8>, ()>, std::vec::Vec<u8>>, [closure@examples/http.rs:158:46: 163:6]>`
    = note: required because it appears within the type `futures::AndThen<futures::MapErr<hyper::client::FutureResponse, [closure@examples/http.rs:158:29: 158:35]>, futures::stream::Fold<futures::stream::MapErr<hyper::Body, [closure@examples/http.rs:159:28: 159:34]>, [closure@examples/http.rs:159:49: 162:10], std::result::Result<std::vec::Vec<u8>, ()>, std::vec::Vec<u8>>, [closure@examples/http.rs:158:46: 163:6]>`
    = note: required because it appears within the type `futures::MapErr<futures::AndThen<futures::MapErr<hyper::client::FutureResponse, [closure@examples/http.rs:158:29: 158:35]>, futures::stream::Fold<futures::stream::MapErr<hyper::Body, [closure@examples/http.rs:159:28: 159:34]>, [closure@examples/http.rs:159:49: 162:10], std::result::Result<std::vec::Vec<u8>, ()>, std::vec::Vec<u8>>, [closure@examples/http.rs:158:46: 163:6]>, [closure@examples/http.rs:164:18: 164:24]>`
    = note: required because it appears within the type `impl futures::Future`
    = note: required by `relm::connect`

error[E0277]: the trait bound `futures::Future<Error=hyper::Error, Item=hyper::client::Response> + 'static: std::marker::Send` is not satisfied
   --> examples/http.rs:138:24
    |
138 |                 return connect(http_future, NewImage, &self.stream);
    |                        ^^^^^^^ the trait `std::marker::Send` is not implemented for `futures::Future<Error=hyper::Error, Item=hyper::client::Response> + 'static`
    |
    = note: `futures::Future<Error=hyper::Error, Item=hyper::client::Response> + 'static` cannot be sent between threads safely
    = note: required because of the requirements on the impl of `std::marker::Send` for `std::ptr::Unique<futures::Future<Error=hyper::Error, Item=hyper::client::Response> + 'static>`
    = note: required because it appears within the type `std::boxed::Box<futures::Future<Error=hyper::Error, Item=hyper::client::Response> + 'static>`
    = note: required because it appears within the type `hyper::client::FutureResponse`
    = note: required because it appears within the type `futures::MapErr<hyper::client::FutureResponse, [closure@examples/http.rs:158:29: 158:35]>`
    = note: required because it appears within the type `futures::future::chain::Chain<futures::MapErr<hyper::client::FutureResponse, [closure@examples/http.rs:158:29: 158:35]>, futures::stream::Fold<futures::stream::MapErr<hyper::Body, [closure@examples/http.rs:159:28: 159:34]>, [closure@examples/http.rs:159:49: 162:10], std::result::Result<std::vec::Vec<u8>, ()>, std::vec::Vec<u8>>, [closure@examples/http.rs:158:46: 163:6]>`
    = note: required because it appears within the type `futures::AndThen<futures::MapErr<hyper::client::FutureResponse, [closure@examples/http.rs:158:29: 158:35]>, futures::stream::Fold<futures::stream::MapErr<hyper::Body, [closure@examples/http.rs:159:28: 159:34]>, [closure@examples/http.rs:159:49: 162:10], std::result::Result<std::vec::Vec<u8>, ()>, std::vec::Vec<u8>>, [closure@examples/http.rs:158:46: 163:6]>`
    = note: required because it appears within the type `futures::MapErr<futures::AndThen<futures::MapErr<hyper::client::FutureResponse, [closure@examples/http.rs:158:29: 158:35]>, futures::stream::Fold<futures::stream::MapErr<hyper::Body, [closure@examples/http.rs:159:28: 159:34]>, [closure@examples/http.rs:159:49: 162:10], std::result::Result<std::vec::Vec<u8>, ()>, std::vec::Vec<u8>>, [closure@examples/http.rs:158:46: 163:6]>, [closure@examples/http.rs:164:18: 164:24]>`
    = note: required because it appears within the type `impl futures::Future`
    = note: required by `relm::connect`

So I wonder if there is a type that is not Send in hyper.
Or perhaps it is caused by something else.
Could you please help me to make this example working?

By the way, is there a better way to write the http_get function?
I would like to keep the error instead of ignoring it.
And I wonder how to avoid using fold.

Thanks for your help.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions