rust-cargo

Downloading Rust crates using a web browser

孤街浪徒 提交于 2019-12-10 14:04:14
问题 Is there any way to download Rust dependencies using a web browser? I currently have internet access through my web browser but not through the command prompt (Windows). I know that I can set up a local fileserver and set Cargo to use a mirror, but that doesn't help if I can't get the crates in the first place. Edit: See related Github issue, now closed. 回答1: You can use the following address: https://crates.io/api/v1/crates/name/version/download To download crates directly from crates.io -

How can I globally configure a Cargo profile option?

喜夏-厌秋 提交于 2019-12-10 13:52:54
问题 With Cargo, I can set a project's development settings to use parallel code generation: [profile.dev] codegen-units = 8 According to the documentation, it should be possible to put this into ~/.cargo/config to apply this setting to all projects. This doesn't work for me: it seems that the .cargo/config file isn't used at all. Is there any way to apply such configuration to every project I compile? 回答1: You can set rustflags for all builds or per target in your .cargo/config file. [build] # or

Is it possible to get the expansion of a single macro instead of the whole file?

天大地大妈咪最大 提交于 2019-12-09 07:21:23
问题 I just found How do I see the expanded macro code that's causing my compile error?. Is it possible to get the expansion of a single macro instead of the whole file? 回答1: The cargo-expand command is really just a thin wrapper around cargo rustc -- -Zunstable-options --pretty=expanded , which is itself a blunt instrument. You can't target a specific macro. However, since version 0.4, you can reduce some noise by specifying an extra path argument to expand only macros used by that module: $

Json Serialization feature of chrono crate

我怕爱的太早我们不能终老 提交于 2019-12-08 19:07:26
问题 I'm trying to use DateTime from rust-chrono crate to my own trait. #[derive(Debug, RustcEncodable, RustcDecodable)] pub struct Accomplishment { name: String, accomplishment_type: String, date: DateTime<UTC> } When I try to compile this it complains that src/lib.rs:11:33: 11:47 error: the trait `rustc_serialize::serialize::Decodable` is not implemented for the type `chrono::datetime::DateTime<chrono::offset::utc::UTC>` [E0277] src/lib.rs:11 #[derive(Debug, RustcEncodable, RustcDecodable)] When

How to limit the number of test threads in Cargo.toml?

北城余情 提交于 2019-12-08 17:11:58
问题 I have tests which share a common resource and can't be executed concurrently. These tests fail with cargo test , but work with RUST_TEST_THREADS=1 cargo test . I can modify the tests to wait on a global mutex, but I don't want to clutter them if there is any simpler way to force cargo set this environment variable for me. 回答1: As of Rust 1.18, there is no such thing. In fact, there is not even a simpler option to disable parallel testing. Source However, what might help you is cargo test --

Run additional tests by using a feature flag to “cargo test”

房东的猫 提交于 2019-12-08 17:07:48
问题 I have some tests that I would like to ignore when using cargo test and only run when explicitly passed a feature flag. I know this can be done by using #[ignore] and cargo test -- --ignored , but I'd like to have multiple sets of ignored tests for other reasons. I have tried this: #[test] #[cfg_attr(not(feature = "online_tests"), ignore)] fn get_github_sample() {} This is ignored when I run cargo test as desired, but I can't get it to run. I have tried multiple ways of running Cargo but the

Where does `multirust` install the Rust language source code?

元气小坏坏 提交于 2019-12-08 15:57:57
问题 I installed the multirust version of the Rust programming language. I was trying to configure the racer code completion package to point to the Rust source code through the RUST_SRC_PATH environment variable. However, I can't seem to find the location of the rust source files. When I type which rustc I am pointed to /usr/local/bin probably because there is a symlink to the actual source directory or something. Any info on where the proper directory for the RUST_SRC_PATH variable is for

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

半世苍凉 提交于 2019-12-08 15:44:53
问题 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) => { 42 + $arg }; // but not this one ($arg:expr) => { mc!(@impl, $arg) }; } 回答1: I guess this is the optimum solution: /// Not meant to be called directly #[doc(hidden)] #[macro_export] macro_rules! hidden { ( $hidden_rule1:expr ) => { ... }; ( $hidden_rule2

How to compile a Rust kernel with an Assembly (NASM) bootloader

旧城冷巷雨未停 提交于 2019-12-08 12:50:59
问题 I have a simple 2-stage bootloader written in NASM, and I want to continue the OS kernel using Rust. So I created a nightly Rust project with Cargo, and disabled std in the src/main.rs file. Now I am trying to link the Assembly files with the Cargo project, but without any success. How should I compile and link the NASM bootloader with the Rust kernel? 回答1: After a couple of hours I compiled the code. The solution was (like Michael Petch suggested), to compile the assembly code into static .o

How to generate Cargo.lock based on last month's crates.io?

为君一笑 提交于 2019-12-06 22:16:37
问题 I want to create a Cargo.lock file in a Rust project from Cargo.toml based on what was available on 22 Feb 2017. I need to make version selection compatible to what would happen on that specific day. (No, don't have a version controlled Cargo.lock around somewhere.) I tried this to no avail: Clone the crates.io index into a local directory and check out an older commit that matches the desired date. Use the following lines in .cargo/config: [source.mycrates] registry = "file:///path/to/crates