tower-rs / tower-h2

An HTTP/2.0 client and server `Service` implementation.
MIT License
89 stars 18 forks source link

Server::new does not impose bounds on Executor #43

Closed mzabaluev closed 5 years ago

mzabaluev commented 5 years ago

The constructor Server::new does not restrict the type parameter for the executor, so it can be used with any mistakenly used argument in that position, e.g., with a reactor::Handle from crate tokio (an easy mistake to make, since the examples use the reactor handle from tokio-core which does implement Executor). This then results in daunting compiler error messages down the road when a Connection accepted by the server is used. When the user-provided types are generated for tower-grpc, it requires some sleuthing work to track back to what is at fault here:

no method named map_err found for type tower_h2::server::Connection<tokio::net::TcpStream, my_proto::server::NodeServer<MyGrpcServer>, tokio::reactor::Handle, my_proto::server::node::ResponseBody<MyGrpcServer>, ()> in the current scope

note: the method `map_err` exists but the following trait bounds were not satisfied:
          `tower_h2::server::Connection<tokio::net::TcpStream, my_proto::server::NodeServer<MyGrpcServer>, tokio::reactor::Handle, my_proto::server::node::ResponseBody<MyGrpcServer>, ()> : futures::Future`
          `&mut tower_h2::server::Connection<tokio::net::TcpStream, my_proto::server::NodeServer<MyGrpcServer>, tokio::reactor::Handle, my_proto::server::node::ResponseBody<MyGrpcServer>, ()> : futures::Future`
          `&mut tower_h2::server::Connection<tokio::net::TcpStream, my_proto::server::NodeServer<MyGrpcServer>, tokio::reactor::Handle, my_proto::server::node::ResponseBody<MyGrpcServer>, ()> : futures::Stream` [E0599]