我正在尝试 Rust 并尝试按照这个示例执行一个简单的 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"
我再次建造
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
文档,但我似乎迷路了。