Category "rust"

Why is capitalizing the first letter of a string so convoluted in Rust?

I'd like to capitalize the first letter of a &str. It's a simple problem and I hope for a simple solution. Intuition tells me to do something like this: le

In Rust, is there a way to iterate through the values of an enum?

I come from a Java background and I might have something like enum Direction { NORTH, SOUTH, EAST, WEST} and I could do something with each of the values in tur

concat string using format!() and return to &'static str [duplicate]

I'll get error when compiled: 'returns value referencing data owned by the current function' here's the code: fn return_static_str(a: &'st

Pick preferred implementation on conflicting trait implementation (using negative bounds)

I am working on a Rust program where I got stuck on a problem that can be reduced to following case: struct Pair<L, R> { left: L, right: R, } // Retu

Is there an equivalent of JavaScript's indexOf for Rust arrays?

var fruits = ["Banana", "Orange", "Apple", "Mango"]; var index = fruits.indexOf("Apple"); let fruits = ["Banana", "Orange", "Apple", "Mango"]; let index = fru

How to overlay data structures?

I have an 8k buffer of bytes. The data in the first part of the buffer is highly structured, with a set of variables of size u32 and u16. The data in the later

How do we install rustc, cargo for all the users in the same linux machine?

I have a ubuntu machine with multiple users some of whom have and have not root privileges. Above that I have a limited storage for the same machine. I really d

How do we install rustc, cargo for all the users in the same linux machine?

I have a ubuntu machine with multiple users some of whom have and have not root privileges. Above that I have a limited storage for the same machine. I really d

How do I write a GROUP BY or HAVING clause in Diesel?

I'm trying to convert the following SQL query into corresponding Rust Diesel code: SELECT COUNT(*) FROM BookStore WHERE BookName IN ('Lord of the Rings', 'Hobbi

How to mock function on unit test actix web

I have an api service that has 2 layer: api and repository. The api layer is where the request handling and business logic defined, while repository is a databa

How do I have a hidden console when using windows_subsystem?

My goal is to have it so when the executable is just double clicked no console spawns but also have it able to print to the console when the user launches it fr

Rust egui window size and dark mode

I'm tring to make a native gui app using egui. After some time got the hello_world example to compile.Heres the code: use eframe::{epi, egui}; struct MyEguiApp

How do I compile Rust code without linking, i.e. produce object files?

Due to how the LGPL works, compiling Rust code to an object file without linking would be useful to be able to do. However, I cannot find any documentation on h

How to get the body of a Response in actix_web unit test?

I'm building a web API service with Rust and actix_web. I want to test a route and check if the received response body is what I expect. But I'm struggling with

How to get the body of a Response in actix_web unit test?

I'm building a web API service with Rust and actix_web. I want to test a route and check if the received response body is what I expect. But I'm struggling with

How can I create parameterized tests in Rust?

I want to write test cases that depend on parameters. My test case should be executed for each parameter and I want to see whether it succeeds or fails for each

Is there a way to open a desktop app as a "subview" inside a Tauri app?

I am building my first app with Tauri framework. Basically, I would like to open as embedded "subviews" (as for "IFrame", just to be clear), inside the main pag

How can I use a `rustc` crate?

I'm trying to use a rustc crate in my program. #[macro_use] extern crate rustc; extern crate rustc_typeck; extern crate syntax; extern crate syntax_pos; use ru

How do I persist a struct instance across files?

I want to persist the contents of a struct created in one Rust file into a different Rust file. In this minimal reproduction, command line arguments are used to

Why can I push items into a Vec I am iterating over with a while loop, but not with a for loop?

Like the rust code below: the while loop compiles and runs fine, but for iter version does not compile, due to error: error[E0502]: cannot borrow `v` as mutabl