Hyper: Can not compile examples

Created on 7 Aug 2019  路  3Comments  路  Source: hyperium/hyper

Compile examples/hello.rs with cargo +nightly build
error

error[E0433]: failed to resolve: could not find `main` in `tokio`
  --> test/src/hello.rs:37:10
   |
37 | #[tokio::main]
   |          ^^^^ could not find `main` in `tokio`

warning: unused imports: `Method`, `StatusCode`
 --> zmq_test/src/main.rs:8:19
  |
8 | use hyper::{Body, Method, Request, Response, Server, StatusCode};
  |                   ^^^^^^                             ^^^^^^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

error[E0277]: the trait bound `impl std::future::Future: hyper::rt::Future` is not satisfied
  --> zmq_test/src/main.rs:47:33
   |
47 |         async { Ok::<_, hyper::Error>(service_fn(hello)) }
   |                                       ^^^^^^^^^^ the trait `hyper::rt::Future` is not implemented for `impl std::future::Future`
   |
   = note: required because of the requirements on the impl of `futures::future::IntoFuture` for `impl std::future::Future`
   = note: required by `hyper::service::service_fn`

error[E0277]: the trait bound `impl std::future::Future: hyper::rt::Future` is not satisfied
  --> zmq_test/src/main.rs:43:41
   |
43 |     let server = Server::bind(&addr).serve(make_service_fn(|_| {
   |                                            ^^^^^^^^^^^^^^^ the trait `hyper::rt::Future` is not implemented for `impl std::future::Future`
   |
   = note: required because of the requirements on the impl of `futures::future::IntoFuture` for `impl std::future::Future`
   = note: required by `hyper::service::make_service_fn`

error[E0277]: the trait bound `hyper::service::make_service::MakeServiceFn<[closure@zmq_test/src/main.rs:43:57: 48:3]>: hyper::service::MakeService<&'a hyper::server::conn::AddrStream>` is not satisfied
  --> zmq_test/src/main.rs:43:35
   |
43 |     let server = Server::bind(&addr).serve(make_service_fn(|_| {
   |                                      ^^^^^ the trait `hyper::service::MakeService<&'a hyper::server::conn::AddrStream>` is not implemented for `hyper::service::make_service::MakeServiceFn<[closure@zmq_test/src/main.rs:43:57: 48:3]>`
   |
   = help: the following implementations were found:
             <hyper::service::make_service::MakeServiceFn<F> as hyper::service::MakeService<&'c Ctx>>
   = note: required because of the requirements on the impl of `hyper::service::MakeServiceRef<hyper::server::conn::AddrStream>` for `hyper::service::make_service::MakeServiceFn<[closure@zmq_test/src/main.rs:43:57: 48:3]>`

error[E0277]: the trait bound `hyper::Server<hyper::server::conn::AddrIncoming, hyper::service::make_service::MakeServiceFn<[closure@zmq_test/src/main.rs:43:57: 48:3]>>: std::future::Future` is not satisfied
  --> zmq_test/src/main.rs:52:2
   |
52 |     server.await?;
   |     ^^^^^^^^^^^^ the trait `std::future::Future` is not implemented for `hyper::Server<hyper::server::conn::AddrIncoming, hyper::service::make_service::MakeServiceFn<[closure@zmq_test/src/main.rs:43:57: 48:3]>>`
   |
   = note: required by `std::future::poll_with_tls_context`

error[E0277]: `main` has invalid return type `impl std::future::Future`
  --> zmq_test/src/main.rs:38:24
   |
38 | pub async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
   |                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `main` can only return types that implement `std::process::Termination`
   |
   = help: consider using `()`, or a `Result`

error[E0277]: the trait bound `impl std::future::Future: hyper::rt::Future` is not satisfied
  --> zmq_test/src/web/router.rs:19:66
   |
19 |     let service = make_service_fn(|_| async { Ok::<_, hyper::Error>(service_fn(router_fn)) });
   |                                                                     ^^^^^^^^^^ the trait `hyper::rt::Future` is not implemented for `impl std::future::Future`
   |
   = note: required because of the requirements on the impl of `futures::future::IntoFuture` for `impl std::future::Future`
   = note: required by `hyper::service::service_fn`

error[E0277]: the trait bound `impl std::future::Future: hyper::rt::Future` is not satisfied
  --> zmq_test/src/web/router.rs:19:16
   |
19 |     let service = make_service_fn(|_| async { Ok::<_, hyper::Error>(service_fn(router_fn)) });
   |                   ^^^^^^^^^^^^^^^ the trait `hyper::rt::Future` is not implemented for `impl std::future::Future`
   |
   = note: required because of the requirements on the impl of `futures::future::IntoFuture` for `impl std::future::Future`
   = note: required by `hyper::service::make_service_fn`

error[E0308]: mismatched types
  --> zmq_test/src/web/router.rs:21:28
   |
21 |     let server = Server::bind(&addr).serve(service);
   |                               ^^^^^ expected enum `std::net::SocketAddr`, found &str
   |
   = note: expected type `&std::net::SocketAddr`
              found type `&&str`

error[E0277]: the trait bound `hyper::service::make_service::MakeServiceFn<[closure@zmq_test/src/web/router.rs:19:32: 19:90]>: hyper::service::MakeService<&'a hyper::server::conn::AddrStream>` is not satisfied
  --> zmq_test/src/web/router.rs:21:35
   |
21 |     let server = Server::bind(&addr).serve(service);
   |                                      ^^^^^ the trait `hyper::service::MakeService<&'a hyper::server::conn::AddrStream>` is not implemented for `hyper::service::make_service::MakeServiceFn<[closure@zmq_test/src/web/router.rs:19:32: 19:90]>`
   |
   = help: the following implementations were found:
             <hyper::service::make_service::MakeServiceFn<F> as hyper::service::MakeService<&'c Ctx>>
   = note: required because of the requirements on the impl of `hyper::service::MakeServiceRef<hyper::server::conn::AddrStream>` for `hyper::service::make_service::MakeServiceFn<[closure@zmq_test/src/web/router.rs:19:32: 19:90]>`

error[E0277]: the trait bound `hyper::Server<hyper::server::conn::AddrIncoming, hyper::service::make_service::MakeServiceFn<[closure@zmq_test/src/web/router.rs:19:32: 19:90]>>: std::future::Future` is not satisfied
  --> zmq_test/src/web/router.rs:25:2
   |
25 |     server.await?;
   |     ^^^^^^^^^^^^ the trait `std::future::Future` is not implemented for `hyper::Server<hyper::server::conn::AddrIncoming, hyper::service::make_service::MakeServiceFn<[closure@zmq_test/src/web/router.rs:19:32: 19:90]>>`
   |
   = note: required by `std::future::poll_with_tls_context`

error: aborting due to 11 previous errors

Some errors have detailed explanations: E0277, E0308, E0433.
For more information about an error, try `rustc --explain E0277`


Most helpful comment

The fix is to change how tokio is added in the toml file. Doing:
tokio = { version = "0.2.6", features = ["full"] }
seems to resolve the issue.

All 3 comments

Master should be working again.

error[E0433]: failed to resolve: could not find main in tokio
--> src/main.rs:5:10
|
5 | #[tokio::main]
| ^^^^ could not find main in tokio

error: cannot find macro log! in this scope
--> src/main.rs:12:5

The fix is to change how tokio is added in the toml file. Doing:
tokio = { version = "0.2.6", features = ["full"] }
seems to resolve the issue.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

belst picture belst  路  3Comments

gabisurita picture gabisurita  路  4Comments

seanmonstar picture seanmonstar  路  5Comments

FGRibreau picture FGRibreau  路  4Comments

mcseemk picture mcseemk  路  3Comments