Search code examples
rusthyper

Why are multiple imports from the Hyper crate failing?


I'm working on a very simple HTTP client in Rust, built on top of the hyper (GitHub, crates.io) crate.

When I try to replicate the examples/client.rs file in a new Cargo project using cargo build (as well as using rustc src/main.rs), I get multiple errors caused by failed imports from hyper.

Here's the top of my main.rs:

extern crate hyper;

use hyper::client::{Client, Request, Response, DefaultTransport as HttpStream};
use hyper::header::Connection;
use hyper::{Decoder, Encoder, Next};

The rest of the file is, except for some comments, identical to the examples/client.rs file from the hyper repository.

At compile time, I get the following errors:

src/main.rs:10:48: 10:78 error: unresolved import `hyper::client::DefaultTransport`. There is no `DefaultTransport` in `hyper::client` [E0432]
src/main.rs:10 use hyper::client::{Client, Request, Response, DefaultTransport as HttpStream};
                                                              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/main.rs:10:48: 10:78 help: run `rustc --explain E0432` to see a detailed explanation
src/main.rs:12:13: 12:20 error: unresolved import `hyper::Decoder`. There is no `Decoder` in `hyper` [E0432]
src/main.rs:12 use hyper::{Decoder, Encoder, Next};
                           ^~~~~~~
src/main.rs:12:13: 12:20 help: run `rustc --explain E0432` to see a detailed explanation
src/main.rs:12:22: 12:29 error: unresolved import `hyper::Encoder`. There is no `Encoder` in `hyper` [E0432]
src/main.rs:12 use hyper::{Decoder, Encoder, Next};
                                    ^~~~~~~
src/main.rs:12:22: 12:29 help: run `rustc --explain E0432` to see a detailed explanation
src/main.rs:12:31: 12:35 error: unresolved import `hyper::Next`. There is no `Next` in `hyper` [E0432]
src/main.rs:12 use hyper::{Decoder, Encoder, Next};
                                             ^~~~
src/main.rs:12:31: 12:35 help: run `rustc --explain E0432` to see a detailed explanation
src/main.rs:53:6: 53:40 error: trait `hyper::client::Handler` is not in scope [E0405]
src/main.rs:53 impl hyper::client::Handler<HttpStream> for Dump {
                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/main.rs:53:6: 53:40 help: run `rustc --explain E0405` to see a detailed explanation
src/main.rs:53:6: 53:40 help: you can to import it into scope: `use hyper::server::Handler;`.

In case it may contribute to this issue, here are the contents of my Cargo.toml:

name = "my_project"
version = "0.0.1"
authors = ["email@example.com"]

[dependencies]
getopts = "0.2"
hyper = "0.9.6"

[[bin]]
name = "my_project"

Some of the imports are actually working, so assuming the example in the repository is up to date, I really can't tell what's wrong. The source files of the crate look like they expose the involved types, but I'm very new to Rust so I may be misreading the files.


Solution

  • You are using examples from the master branch that do not work with 0.9.6 version. You can take a look at examples on the branch 0.9.6 or make cargo use hyper direct from github, writing on Cargo.toml:

    [dependencies]                                     
    hyper = {git = "https://github.com/hyperium/hyper"}