rust-cargo

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

倖福魔咒の 提交于 2019-11-27 15:23:12
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; | ^^^^^^^^ Did you mean `self::url`? error[E0432]: unresolved import `http::client::RequestWriter` --> src

How can I build multiple binaries with Cargo?

别等时光非礼了梦想. 提交于 2019-11-27 10:41:04
问题 I'd like to make a project with a daemon and a client , connecting through a unix socket. A client and a daemon requires two binaries, so how do I tell Cargo to build two targets from two different sources? To add a bit of fantasy, I'd like to have a library for the main part of the daemon , and just have a binary to wrap around it and communicate through sockets. So, we have this kind of tree architecture: ├── Cargo.toml ├── target | └── debug | ├── daemon │ └── client └── src ├── daemon │ ├

Is it possible to have Cargo always show warnings?

家住魔仙堡 提交于 2019-11-27 05:49:45
问题 I'm using watch with cargo , in order to quickly see compile time errors. However, cargo build will only show errors when building the first time. $ cargo build Compiling clayman v0.0.1 src/core_math/vector.rs:8:5: 13:6 warning: method is never used: `New`, #[warn(dead_code)] on by default src/core_math/vector.rs:8 pub fn New(x: i32, y: i32) -> Vector { src/core_math/vector.rs:9 Vector { src/core_math/vector.rs:10 x: x, src/core_math/vector.rs:11 y: y src/core_math/vector.rs:12 } src/core

What is an idiomatic way to have shared utility functions for integration tests and benchmarks?

北城余情 提交于 2019-11-27 04:48:49
问题 I have Rust project with both integration tests (in the /tests dir) and benchmarks (in the /benches dir). There are a couple of utility functions that I need in tests and benches, but they aren't related to my crate itself, so I can't just put them in the /utils dir. What is idiomatic way to handle this situation? 回答1: Create a shared crate (preferred) As stated in the comments, create a new crate. You don't have to publish the crate to crates.io . Just keep it as a local unpublished crate

OpenSSL crate fails compilation on Mac OS X 10.11

别说谁变了你拦得住时间么 提交于 2019-11-27 04:07:16
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") debug=true opt-level=0 HOST = Some("x86_64-apple-darwin") TARGET = Some("x86_64-apple-darwin") TARGET = Some(

Linking Rust application with a dynamic library not in the runtime linker search path

 ̄綄美尐妖づ 提交于 2019-11-26 22:59:45
问题 I have a shared library that I'd like to dynamically link into several separate binary Cargo applications. I include its location in the linker using the -- -L /path/to/dir format and the application compiles correctly with the significant decrease in binary size I expect. However, when checking the generated binary using ldd , I get a message saying that the library couldn't be found: casey@Gilthar-II:~/bot4/backtester/target/release$ ldd backtester linux-vdso.so.1 => (0x00007ffc642f7000)

How do I 'pass down' feature flags to subdependencies in Cargo?

ぐ巨炮叔叔 提交于 2019-11-26 22:01:32
问题 I'm writing a library in Cargo. If this library depends on another library like libc, which exposes a feature (in this case, use_std ), how do I make a feature I expose enable or disable that feature in my dependency? Looking at the cargo documentation, it looks like there's no official way specified to do this. 回答1: From the documentation you linked to: # Features can be used to reexport features of other packages. The `session` # feature of package `awesome` will ensure that the `session`

How do I specify the linker path in Rust?

血红的双手。 提交于 2019-11-26 21:20:49
问题 I'm trying to link a Rust program with libsoundio. I'm using Windows and there's a GCC binary download available. I can link it like this if I put it in the same folder as my project: #[link(name = ":libsoundio-1.1.0/i686/libsoundio.a")] #[link(name = "ole32")] extern { fn soundio_version_string() -> *const c_char; } But I really want to specify #[link(name = "libsoundio")] or even #[link(name = "soundio")] , and then provide a linker path somewhere else. Where can I specify that path? I

Rust package with both a library and a binary?

删除回忆录丶 提交于 2019-11-26 19:28:10
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? Doug 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" path = "src/bin.rs" src/lib.rs: pub fn test() { println!("Test"); } src/bin.rs: extern crate mylib; /

What is a crate attribute and where do I add it?

余生长醉 提交于 2019-11-26 19:03:27
In order to get a feel for how Rust works, I decided to look at a little terminal-based text editor called Iota . I cloned the repository and ran cargo build only to be told: error: *if let* syntax is experimental help: add #![feature(if_let)] to the crate attributes to enable Where am I supposed to add #![feature(if_let)] to the crate attributes? A crate attribute is an attribute ( #[...] ) that applies to the enclosing context ( #![...] ). This attribute must be added to the top of your crate root , thus the context is the crate itself: #![attribute_name] #![attribute_name(arg1, ...)] If you