Category "rust"

How do you run the main binary and then run tests based on it in Rust?

I have written a webserver which requires some complicated setup and teardown, and am trying to write unit tests. Axum does provide examples using the Tower One

How do I separate the execution of tests via cargo test?

I'm working on a Rust project that has many units test (almost 200). About 20 of those tests are really heavy and they create problems when executed with the ot

Use rust cargo to run tests in workspace root

I've got the following rust project layout: project_name ├── crate_1 │ ├── src │ │ ...

I cant install cargo afl due to conflict libc in build

i run this command for installing afl but got this error :slight_smile: cargo install --force afl --verbose Updating crates.io index Installing afl v0.12.2 Comp

How to reset the console output? Clearing just shifts the output back

My console application needs to clear the screen. How do I truly clear the screen, like the reset command in Linux? I tried using methods I found on Google, li

How to put mathematical equations in source code without making it unreadable?

When implementing complex calculations, I found that readability suffered a lot. For example, this formula is absolutely unreadable when translated to code (I c

How do I automatically run "cargo fix" on save in VSCode?

Currently, I use VSCode as my IDE when programming Rust. I use the rust-analyzer VSCode extension, since it seems to be the best one out there for Rust (as of 2

How can we detect the host OS type (not the target OS) in Rust?

There are many ways to detect the target OS, e.g. #[cfg(windows)], #[cfg(unix)], std::env::consts::OS. For cross-compilation, how can we detect the OS that our

Why does vscode's "Run Doctest" helper filter all of my crate's Doctests?

Expected Behavior: Clicking "Run doctest" in vscode should execute one test from doctest snippets. Terminal output SHOULD say ("1 passed;" or "1 failed;"), and

rust-analyzer failed to load workspace: Failed to read Cargo metadata from Cargo.toml file e:\rustBlog\server\Cargo.toml

enter image description here **I create rust project by "cargo new [name]" and install rust-analyzer in vsCode.But when I open the project by vscode,there's an

What does the asterisk / star (*) at the end of a cargo tree output represent?

What does the asterisk / star (*) at the end of a cargo tree output represent? How and where is it used?

Crate p12 rust - Error [E0599]: no method name `decrypt_padded_vec`found for struct `Decryptor` - in docker build

my docker builds started failing today and I can't seem to figure out exactly how to fix it. Compiling locally is still working. When I try to create a containe

Solana Test Program Anchor Test failing tsconfig.json" > needs an import assertion of type "json"

I ran anchor test --skip-deploy and all it should do is initialise my program, but all I get is this error, that I cannot resolve. I checked the tsconfig.json s

Writing a Rust struct type that contains a string and can be used in a constant

I'm getting started with Rust. I want to have a struct that contains (among other things) a string: #[derive(Clone, Debug)] struct Foo { string_field: &

What is this question mark operator about?

I'm reading the documentation for File: //.. let mut file = File::create("foo.txt")?; //.. What is the ? in this line? I do not recall seeing it in the Rust

Rust: additional trait bounds in conjunction with higher-ranked lifetime bounds

I want trait implementations in Rust to be able to return arbitrary iterators (of specific item type) that may reference the original object with a lifetime 'a

Does Cargo support custom profiles?

I often want to compile in release mode with debug = true so that I can read the generated assembly a bit easier. I am currently doing this: [profile.release]

How to get the number of elements (variants) in an enum as a constant value?

Is there a way to extract the number of elements in an enum? Simple example (with imaginary number_of_elements method): enum FooBar { A = 0, B, C, }; println

Contradictory error messages calling .any() on &dyn Iterator vs &mut dyn Iterator

MCVE (simplified from real code where I may return a raw vec.iter(), or a vec.iter().filter() based on some conditions): let input = vec![1,2,3]; let dyn_iter:

Improving Rust binary build times

I’m just starting a Rust project and already it takes ~7.6s to build what I’d consider a simple binary. I’m using async/await a lot and comme