我正在使用Rust中一个非常简单的HTTP客户端,它建立在hyper
(GitHub,crates.io)包的顶部。
当我尝试使用examples/client.rs
(以及使用cargo build
)在新的Cargo项目中复制rustc src/main.rs
文件时,我会因{{1}导入失败而导致多个错误}}
这是hyper
的顶部:
main.rs
除了一些注释之外,文件的其余部分与extern crate hyper;
use hyper::client::{Client, Request, Response, DefaultTransport as HttpStream};
use hyper::header::Connection;
use hyper::{Decoder, Encoder, Next};
存储库中的examples/client.rs
文件相同。
在编译时,我收到以下错误:
hyper
如果它可能导致此问题,以下是我的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;`.
:
Cargo.toml
有些导入实际上正在运行,所以假设存储库中的示例是最新的,我真的不能说出错误。箱子的源文件看起来像是暴露了所涉及的类型,但我对Rust来说很新,所以我可能误读了这些文件。
答案 0 :(得分:5)
您正在使用主分支中不适用于0.9.6
版本的示例。您可以查看分支0.9.6
上的示例,或直接从github使用hyper
,在Cargo.toml
上写一下:
[dependencies]
hyper = {git = "https://github.com/hyperium/hyper"}