Questions tagged [rust-cargo]

Cargo is the official package manager for the Rust programming language.

Cargo is the official package manager for the Rust programming language. Using a manifest, the programmer can provide metadata about a project, including dependencies, which Cargo can automatically download and compile before compiling the project itself.

You can find more information in the cargo book and browse the crates (Rust packages) in crates.io.

2044 questions
14
votes
2 answers

Is there a way to hide a macro pattern from docs?

As of Rust 1.6.0, the generated documentation hides the implementation of each macro pattern: Is there a way to hide some of the patterns from the Cargo-generated docs? macro_rules! mc { // hide this entire pattern (@impl, $arg:expr) => {…
dragostis
  • 2,574
  • 2
  • 20
  • 39
14
votes
1 answer

How to run library tests and doc tests but not integration tests

Is it possible to use the cargo command to run library tests (i.e.., cargo test --lib) and documentation tests without running any integration tests (i.e., the tests in the crate's top-level tests directory)? Bonus points are awarded for compiling…
Craig M. Brandenburg
  • 3,354
  • 5
  • 25
  • 37
14
votes
3 answers

Is there a way to store the version information in a Rust compiled executable or library?

When a Rust binary (executable or dylib) is built, the version information configured in Cargo.toml has no effect on the binary built, meaning the configured version is not stored inside the binary file. In Linux, when I use readelf -V for a .so…
palazzo train
  • 3,229
  • 1
  • 19
  • 40
14
votes
3 answers

Disable registry update in Cargo

How do I disable cargo update or cargo build from attempting to access github.com; but still download the appropriate package from crates.io I have a single dependency in my cargo.toml [dependencies] chrono = "0.2.14" Running cargo build E:\>cargo…
Delta_Fore
  • 3,079
  • 4
  • 26
  • 46
14
votes
1 answer

How do I use a feature of a dependency only for testing?

Say, I have a crate with a dependency that has an optional feature. Now this feature is mostly useful for testing, but the crate itself is a dependency for the whole code. Is it possible to instruct cargo to use the feature only for testing? In my…
Emilia Bopp
  • 866
  • 10
  • 20
13
votes
1 answer

How can I set default authors for new Cargo projects?

When creating a new project with cargo new, I would like to have the Cargo.toml file automatically include a predefined authors field. The Rust book said: The next four lines set the configuration information Cargo needs to compile your program:…
Galarmo
  • 303
  • 3
  • 7
13
votes
2 answers

Can I set Cargo project's default features depending on the platform?

Is it possible to make the list of default features platform dependent in your Cargo.toml? I'd like to use features to select platform-dependent dependencies. I'd imagine something like this: [features] # on Unix default = ["feature-a"] # not on…
Tim Visée
  • 2,988
  • 4
  • 45
  • 55
13
votes
4 answers

How do I make a Rust program which can be executed without using `cargo run`?

How can I make a program in Rust which can be executed from anywhere without using cargo run, by just clicking on the file? Is there any crate? I have written code for snake game and I want to run it by just clicking on a file.
shakaib naqvi
  • 153
  • 1
  • 1
  • 6
13
votes
1 answer

How do I specify features for a sub-dependency in Cargo?

I'm working on a CLI app that uses reqwest and self_update. self_update also uses reqwest. I want my app to use rustls and not pull in openssl dependencies. Cargo.toml allows choosing features of dependencies: [dependencies.reqwest] version =…
Cameron Taggart
  • 5,771
  • 4
  • 45
  • 70
13
votes
1 answer

How do I import multiple versions of the same crate?

As discussed in Is it documented that Cargo can download and bundle multiple versions of the same crate?, it's possible for Cargo to pull in multiple versions of the same crate for a single program. How do I access both of these versions…
Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
13
votes
1 answer

how to run examples of a rust project

1/ It happened to me run examples in this repo https://github.com/0xProject/OpenZKP One of way to an example is cargo run --release --example small_fib I'm just curious why we can run the example small_fib at the root directory even the example…
user602874
  • 1,429
  • 2
  • 12
  • 10
13
votes
4 answers

How to capture the output of a process piped into a Rust program?

I know how to read the command line arguments, but I am having difficulties reading the command output from a pipe. Connect a program (A) that outputs data to my Rust program using a pipe: A | R The program should consume the data line by line as…
AbhiNickz
  • 1,035
  • 2
  • 14
  • 32
13
votes
2 answers

cargo always starts with " Blocking waiting for file lock on build directory"

I recently installed rustup on my Windows machine and incorporated it into Atom as my editor. Everything works fine, but as soon as I do a cargo run on my project, the first thing that Cargo says is: Blocking waiting for file lock on build…
Norbert
  • 735
  • 8
  • 19
13
votes
1 answer

Consolidating cargo dependencies

I have a project that has a dependency (a cookie utility) that has a dependency on iron >= 0.3, <= 0.4. My project has a dependency on iron 0.3 (so I can use the router middleware that hasn't yet been updated to the latest iron). When I try to…
Jacob Brown
  • 7,221
  • 4
  • 30
  • 50
12
votes
1 answer

Is there a way of listing all tests in a Cargo project without running them?

Waiting for a large test suite to run is painful, so I collect the duration of each test from cargo test and use a simple heuristic to find failures fast (I order by probability of failure/last run duration and run tests in that order). This is…
Max Murphy
  • 1,701
  • 1
  • 19
  • 29