Category "rust"

Generic function that returns different types based on the value of an argument

I have a struct which holds registers. I want my read_register function to return a u8 for Register::V0 and Register::V1 but a u16 for Register::V2 and Register

rustup gives command not found error with zsh even after installing with brew

I installed rustup with brew command but still says that rustup command is not found. I am not sure if I am missing any installation step. Any help would be app

How do I idiomatically convert a bool to an Option or Result in Rust?

It seems there is no way of such one-line conversion using std. I do not like this kind of verbosity: match my_bool { true => Ok(()), false => Err

Pass a pointer string as an argument in host import function in Rust WebAassembly (wasmtime)

so I have the following import in my generated .wast file (disclaimer: I have not written the wasm file myself): (import "index" "bigDecimal.fromString" (func

Rust compilation error " failed to run custom build command for `freetype-sys v0.13.1' " win 10

I am trying to build a Rust program on Windows 10 having a GUI. When trying to compile a Rust file with gtk dependency on Windows 10 I keep getting the followin

How to config payload limit for a actix websocket server

I am learning Actix and try creating a WebSocket service code snippets: starts server pub async fn start(addr: &str) -> std::result::Result<(), IoErro

Why is Rust pushing new line into String when pushing optional character? [duplicate]

I am trying an exercise from the end of Chapter 8 in The Rust Programming Language to translate words into pig latin. Unfortunately, I am hav

How do I write a Rust unit test that ensures that a panic has occurred?

I have a Rust function that panics under some condition and I wish to write a test case to validate whether the function is panicking or not. I couldn't find an

How does one create a HashMap with a default value in Rust?

Being fairly new to Rust, I was wondering on how to create a HashMap with a default value for a key? For example, having a default value 0 for any key inserted

Apparent no-op in Rust assembly output?

I was studying the x86_64 assembly for the following function: /// Returns the greatest power of two less than or equal to `self`, or 0 otherwise. pub const fn

using iodbc in Rust

I'm trying to connect to FileMaker through a Rust application (don't ask me why...) - and I run into the wall of the FM ODBC driver being built against iodbc an

How use postgres (deadpool-postgres) with WebSocket Actix (actix-web-actors)

How to use database connection from a WebSocket handler. It is possible to use future.into_actor or ctx.spawn or actix::fut::wrap_future but that's not accurate

Why are the changes I make to my Rust program from VS Code not reflected when I compile?

I'm having a problem with Rust that I strongly suspect has do with a disconnect between Cargo and VS Code. I build my Cargo project with cargo new project I ed

Are nested structs supported in Rust?

When I try to declare a struct inside of another struct: struct Test { struct Foo {} } The compiler complains: error: expected identifier, found keywor

How can I use a HashMap with f64 as key in Rust?

I want to use a HashMap<f64, f64>, for saving the distances of a point with known x and key y to another point. f64 as value shouldn't matter here, the fo

How to combine two vectors of references without consuming an iterator?

I want to combine two reference vectors and convert them into a vector of values without consuming an iterator. Situation: Generate vectors by iterating over sp

How to POST a file using reqwest?

The documentation for reqwest v0.9.18 shows the following example of posting a file: let file = fs::File::open("from_a_file.txt")?; let client = reqwest::Clien

How to skip the first item(s) of an iterator in Rust?

When iterating over arguments (for example) thats the most straightforward way to skip the first N elements? eg: use std::env; fn main() { for arg in env

How to find X in a HashMap of HashMaps?

Given that I know ParentId and ChildId, how would I find the UserId if the hashmap is: HashMap<ParentId, HashMap<ChildId, HashMap<UserId, Foobar>>

How to avoid zombie processes when running a Command?

A small Iron project calls a Command in some route and returns a Response. Here is the relevant code of the route handler function: fn convert(req: &mut Re