Category "rust"

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

Rust tonic tonic::include_proto file path from one module to another module in tonic build

I am implementing gRPC client and server using Tonic. I have two modules each module depending on another module proto file. I am facing an issue when I try to

debugging multiple threads with visual studio code

I am setting some breakpoints in some async threaded code and I can't seem to figure out how to tell visual studio code to catch any threads in this code path.

How can I obtain access to a networked location?

My program, when started up with the system, is unable to access a networked location: fn main() { ensure_network("\\\\SERVER\\".to_string()); } fn ensure_

How to invert a `HashMap<String, MyEnum>`? (Error: "`FromIterator` not implemented for [pair]")

I'm trying to invert a HashMap<String, MyEnum> in Rust, and getting an error: Rust Playground instance Code: use std::collections::HashMap; // Directive

How to get a release build with debugging information when using cargo?

The following command $ cargo build produces a non-optimized build with debugging information. On the contrary, $ cargo build --release produces an optimi

Glob Multiple File Types

I want to find files for some pattern with multiple extensions. Ex:- some/path/**.{json,jsonc} But rust glob function is not working with these types of patt

How do I print colored text to the terminal in Rust?

How do I output colored text to the terminal using Rust? I've tried using the special escape characters that I found in this python answer, but they just print