rust-cargo

Out of source builds (external build directory) with Cargo?

本秂侑毒 提交于 2020-08-01 06:03:45
问题 Having used CMake, I've become used to out-of-source builds, which are encouraged with CMake. How can out-of-source builds be done with Cargo? Using in-source-builds again feels like a step backwards: Development tools need to be configured to ignore paths. Sometimes multiple plugins and development tools - especially using VIM or Emacs! Some tools can't be configured to easily hide build files. While dotfiles are typically hidden, they will still show Cargo.lock and target/ , worse still,

Out of source builds (external build directory) with Cargo?

陌路散爱 提交于 2020-08-01 06:01:00
问题 Having used CMake, I've become used to out-of-source builds, which are encouraged with CMake. How can out-of-source builds be done with Cargo? Using in-source-builds again feels like a step backwards: Development tools need to be configured to ignore paths. Sometimes multiple plugins and development tools - especially using VIM or Emacs! Some tools can't be configured to easily hide build files. While dotfiles are typically hidden, they will still show Cargo.lock and target/ , worse still,

How to specify the exact version of a dependency?

馋奶兔 提交于 2020-07-08 11:58:05
问题 I'm using $ cargo --version cargo 0.21.0-beta (7e00b82d9 2017-07-17) I created a simple project with cargo new --bin test1 , and then I added a dependency: [dependencies] lazy_static = "0.2.2" to Cargo.toml (according to this such version exists) and #[macro_use] extern crate lazy_static; to src/main.rs When I run cargo build : $ cargo build Compiling lazy_static v0.2.8 Compiling test1 v0.1.0 (file:///tmp/test1) warning: unused `#[macro_use]` import --> src/main.rs:1:1 | 1 | #[macro_use] | ^^

How to download the documentation of a crate with Cargo?

六月ゝ 毕业季﹏ 提交于 2020-07-03 06:25:03
问题 In Haskell's Cabal, one can download the documentation for a package. Is it possible with Rust's Cargo? I searched on the Internet but found nothing. 回答1: You can build the documentation for all crates that are currently specified in your Cargo.toml by using the command cargo doc A list of common Cargo commands can be found with cargo --help , and detailed information for a command can be found with cargo COMMAND --help : $ cargo doc --help cargo-doc Build a package's documentation USAGE:

How to avoid hard-coded values in Rust

Deadly 提交于 2020-06-26 04:48:09
问题 Below is a Maven/Java directory structure. - src - main - java - resources - test - java - resources - target Here, the resources folder holds application-related configuration files and resource files, to avoid hard-coding their contents in source files. How can I achieve the same in Rust with Cargo? 回答1: Maven doesn't include everything from your source. In fact, it includes the binary but doesn't even have to include the source at all in a .jar . You can configure it to say what to include

How do I tell Cargo to run files from a directory other than “src”?

你说的曾经没有我的故事 提交于 2020-06-03 16:13:10
问题 I have a front-end project that has a lot of stuff in src folder, and I have the opportunity to also use Rust on the server side. All my Rust server files are in the server folder; how can I tell Cargo to run ./server/app.rs ? 回答1: As stated in the comments, you are probably better off just moving all of your code into the "server" directory. If you don't, you are going to be swimming uphill against defaults, which is not usually a great idea. That being said, you can specify the path to the

How do I tell Cargo to run files from a directory other than “src”?

给你一囗甜甜゛ 提交于 2020-06-03 16:11:40
问题 I have a front-end project that has a lot of stuff in src folder, and I have the opportunity to also use Rust on the server side. All my Rust server files are in the server folder; how can I tell Cargo to run ./server/app.rs ? 回答1: As stated in the comments, you are probably better off just moving all of your code into the "server" directory. If you don't, you are going to be swimming uphill against defaults, which is not usually a great idea. That being said, you can specify the path to the

Using Cargo with my project's own directory structure

末鹿安然 提交于 2020-05-27 12:14:19
问题 Can I use Cargo to build Rust code without using its standard project layout? My source files are not in a directory called src and this will not change. My binaries must end up in the current directory (or, in some other projects, in a different directory that is not called target/SOMETHING ). Can I tell Cargo that executable foo must be built from foo.rs and bar.rs in the same directory as Cargo.toml , and qux from foo.rs ? I don't care about Cargo as a build system or as a deployment

Using Cargo with my project's own directory structure

人走茶凉 提交于 2020-05-27 12:13:26
问题 Can I use Cargo to build Rust code without using its standard project layout? My source files are not in a directory called src and this will not change. My binaries must end up in the current directory (or, in some other projects, in a different directory that is not called target/SOMETHING ). Can I tell Cargo that executable foo must be built from foo.rs and bar.rs in the same directory as Cargo.toml , and qux from foo.rs ? I don't care about Cargo as a build system or as a deployment

How do I tell Cargo to build files other than main.rs?

纵饮孤独 提交于 2020-05-25 04:10:08
问题 Here is my directory structure: lowks@lowkster ~/src/rustlang/gettingrusty $ tree . . ├── Cargo.lock ├── Cargo.toml ├── foo.txt ├── src │ ├── boolean_example.rs │ ├── function_goodbye_world.rs │ ├── listdir.rs │ ├── looping.rs │ ├── main.rs │ ├── pattern_match.rs │ └── write_to_file.rs └── target ├── build ├── deps ├── examples ├── gettingrusty └── native 6 directories, 11 files When I run 'cargo build', it seems to only build main.rs . How should I change Cargo.toml to build the rest of the