rust-cargo

How can a Rust program access metadata from its Cargo package?

為{幸葍}努か 提交于 2019-11-26 18:49:48
问题 How do you access a Cargo package's metadata (e.g. version) from the Rust code in the package? In my case, I am building a command line tool that I'd like to have a standard --version flag, and I'd like the implementation to read the version of the package from Cargo.toml so I don't have to maintain it in two places. I can imagine there are other reasons someone might want to access Cargo metadata from the program as well. 回答1: Cargo passes some metadata to the compiler through environment

Unable to find symbols from extern crates included with `use`

有些话、适合烂在心里 提交于 2019-11-26 17:11:55
问题 I'm trying to use some Rust libraries from crates on Github. This is the first time I've tried to do this. The code, lifted from an "html" library example, begins like this: mod interactive_test { extern crate http; extern crate url; use std::os; use std::str; use url::Url; use http::client::RequestWriter; use http::method::Get; use http::headers::HeaderEnum; // ... } fn main() {} Errors look like this: error[E0432]: unresolved import `url::Url` --> src/main.rs:7:9 | 7 | use url::Url; | ^^^^^

OpenSSL crate fails compilation on Mac OS X 10.11

允我心安 提交于 2019-11-26 11:03:18
问题 I tried to install the Iron framework for Rust on Mac OS X 10.11.2, but it failed when I run cargo build or cargo run on compiling openssl \'s stuff: failed to run custom build command for `openssl-sys-extras v0.7.4` Process didn\'t exit successfully: `/xxx/rust/hello/target/debug/build/openssl-sys-extras-413d6c73b37a590d/build-script-build` (exit code: 101) --- stdout TARGET = Some(\"x86_64-apple-darwin\") OPT_LEVEL = Some(\"0\") PROFILE = Some(\"debug\") TARGET = Some(\"x86_64-apple-darwin\

Rust package with both a library and a binary?

泄露秘密 提交于 2019-11-26 06:14:27
问题 I would like to make a Rust package that contains both a reusable library (where most of the program is implemented), and also an executable that uses it. Assuming I have not confused any semantics in the Rust module system, what should my Cargo.toml file look like? 回答1: Tok:tmp doug$ du -a 8 ./Cargo.toml 8 ./src/bin.rs 8 ./src/lib.rs 16 ./src Cargo.toml: [package] name = "mything" version = "0.0.1" authors = ["me <me@gmail.com>"] [lib] name = "mylib" path = "src/lib.rs" [[bin]] name = "mybin