我正在尝试Rust并尝试在this example之后执行一个简单的HTTP GET请求。首先,我运行cargo new request_learn --bin,然后将示例代码粘贴到main.rs中,然后运行cargo build

request git:(master) ✗ cargo build
   Compiling request v0.0.1 (file:///Users/soliva/Sites/rust/app/request)
src/main.rs:12:23: 12:27 error: macro undefined: 'fail!'
src/main.rs:12         Err(error) => fail!(":-( {}", error),
                                 ^~~~
src/main.rs:17:35: 17:39 error: macro undefined: 'fail!'
src/main.rs:17         Err((_request, error)) => fail!(":-( {}", error),
                                             ^~~~
error: aborting due to 2 previous errors
Could not compile `request`.

我在这里更改了fail!宏,因为似乎没有它。下一个版本说

request git:(master) ✗ cargo build
   Compiling request v0.0.1 (file:///Users/soliva/Sites/rust/app/request)
src/main.rs:1:1: 1:19 error: can't find crate for `http`
src/main.rs:1 extern crate http;
          ^~~~~~~~~~~~~~~~~~
error: aborting due to previous error
Could not compile `request`.

所以我添加到Cargo.toml
[dependencies]
http = "0.0.0"

然后我再次 build

request git:(master) ✗ cargo build --verbose
    Updating registry https://github.com/rust-lang/crates.io-index
   Compiling http v0.0.0-prealpha
   Running `rustc /Users/soliva/.cargo/registry/src/github.com-/.cargo/registry/src/github.com-1ecc6299db9ec823/http-0.0.0-prealpha/src/lib.rs:1:1: 1:20 error: The attribute license is currently unknown to the compiler and may have meaning added to it in the future
error: aborting due to previous error
Could not compile `http`.

Caused by:
  Process didn't exit successfully: `rustc /Users/soliva/.cargo/registry/src/github.com-1ecc6299db9ec823/http-0.0.0-prealpha/src/lib.rs --crate-name http --crate-type lib -g -C metadata=bec89420f16c6bf6 -C extra-filename=-bec89420f16c6bf6 --out-dir /Users/soliva/Sites/rust/app/request/target/debug/deps --emit=dep-info,link -L dependency=/Users/soliva/Sites/rust/app/request/target/debug/deps -L dependency=/Users/soliva/Sites/rust/app/request/target/debug/deps -Awarnings` (exit code: 101)

我剪了一些错误消息,因为它很长并且重复

我想念什么吗?我正在寻找Rust模块和cargo文档,但我似乎迷路了。

最佳答案

嗯,是的Rust-CI

问题是,Rust-CI是一个在Travis甚至是Cargo中支持Rust的站点。在那些黑暗,黑暗的日子里,我们依靠Rust-CI来检测Rust每夜的变化,并自动更新Travis CI,以便我们的构建使用最新的Rust构建。它还用作文档的存储库。

如今,我们使用Cargo并在个人Github Pages文档存储库上托管文档。

无论如何,正如其他人所指出的,rust-http crate 已经过时,建议的替代方法是现在使用hyper crate 。

[dependencies]
hyper = "0.5.0"

这是一个hyper usage example:
extern crate hyper;

use std::io::Read;

use hyper::Client;
use hyper::header::Connection;

fn main() {
    // Create a client.
    let mut client = Client::new();

    // Creating an outgoing request.
    let mut res = client.get("http://www.gooogle.com/")
        // set a header
        .header(Connection::close())
        // let 'er go!
        .send().unwrap();

    // Read the Response.
    let mut body = String::new();
    res.read_to_string(&mut body).unwrap();

    println!("Response: {}", body);
}

关于rust - 无法编译 'http'条板箱,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/30204683/

10-10 18:33
查看更多