Hyper: Example hello.rs doesn't compile

Created on 22 Nov 2019  路  5Comments  路  Source: hyperium/hyper

When trying to compile hello.rs, I get following compiler errors. (Using hyper 0.13.0-alpha.4)

error[E0433]: failed to resolve: use of undeclared type or module `tokio`
  --> src/main.rs:12:3
   |
12 | #[tokio::main]
   |   ^^^^^ use of undeclared type or module `tokio`

error[E0433]: failed to resolve: use of undeclared type or module `pretty_env_logger`
  --> src/main.rs:14:5
   |
14 |     pretty_env_logger::init();
   |     ^^^^^^^^^^^^^^^^^ use of undeclared type or module `pretty_env_logger`

error[E0277]: `main` has invalid return type `impl std::future::Future`
  --> src/main.rs:13:24
   |
13 | 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`

Most helpful comment

Whether or not it's common, I think that for examples like this one it would be helpful to mention the dependencies in the README.

Basically I don't think this needed to be confusing for you, even if you're new to Rust.

All 5 comments

Are you running it from the hyper repo or did you copy the code into your project? Those warnings look like a Cargo.toml without the right dependencies included.

Copied the example. I havn't seen it mentioned anywhere that example should be run as part of hyper repo, or what dependencies should be included.

Not sure how familiar you are with Rust and Cargo. To run all the examples in the repo, you can use cargo run --example <example name>. In this case, cargo run --example hello should work.

If you're going to run the code in your own project, you'll have to add these dependencies to your Cargo.toml:

hyper = "0.13.0-alpha.4"
tokio = "0.2.0-alpha.6"
pretty_env_logger = "0.3.1"

Note that hyper is about to upgrade versions, since tokio recently moved to "0.2.0". But for now you have to use the alphas.

I'm still quite new to Rust. I expected examples to be self-contained, but if it is common in Rust to not mention required dependencies for examples, then I guess this issue should be closed.

Whether or not it's common, I think that for examples like this one it would be helpful to mention the dependencies in the README.

Basically I don't think this needed to be confusing for you, even if you're new to Rust.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

DemiMarie picture DemiMarie  路  25Comments

orangesoup picture orangesoup  路  19Comments

arcrose picture arcrose  路  22Comments

cactorium picture cactorium  路  26Comments

scottlamb picture scottlamb  路  31Comments