Category "rust"

Can't get Rocket's EventStream! to work with borrowed values

This is a pretty specific question related to the Rocket crate. I'm not sure if this is an issue with the crate or if I'm just doing something plain wrong. I'm

Can you deserialize a struct from a map or a string?

Consider this Config struct which contains a vector of Host structs: use serde::Deserialize; use std::net::IpAddr; #[derive(Debug, Deserialize)] struct Config

why does max_by_key with i32.log10() causing "attempt to add with overflow"

I'm trying to get the max number of digits in an i32 array. I'm using log10(n) + 1 as my formula to calculate how many digits an i32 has and I thought I would j

Double dereference operator on self in Deref trait implementation for Box [duplicate]

Looking at implementation of Deref trait for Box: impl<T: ?Sized, A: Allocator> const Deref for Box<T, A> { type Target = T;

Actix-Web reports "App data is not configured" when processing a file upload

I'm using the Actix framework to create a simple server and I've implemented a file upload using a simple HTML frontend. use actix_web::web::Data; use actix_we

Why is a string passed from JavaScript to Wasm always empty in section 4.2 of the Rust/Wasm beginner book?

I'm trying to follow the Rust WebAssembly book and I'm stuck at the exercise in section 4.2. I changed everything as described in the answer, but the given &

Unable to compile Rust hello world on Windows: linker link.exe not found

I have installed Rust on windows from Rust installation page. After installation I tried running the "hello world" program but got the following error. >car

How to bind function with placeholders

How can I do this: auto fn1 = bind(func, _1, 2, 3); (C++ function binding with placeholders) in Rust (possibly without an intermediate closure)?

Rust: how to override the default way of reporting error?

When error occurs in Rust, most Rust standard and 3rd party libraries (e.g. anyhow) would simply print the error message to stdout/stderr. What I need is to ove

Can I pop from a HashSet efficiently?

My algorithm needs to iteratively shrink a set by removing an element, and do something with the element removed and with the shrinking set in each iteration. A

Rust actix-web middleware modifying request data

Is there a recommended way of modifying the request received on actix-web. Is there an example on how to modify I am looking for way to add data to the request

Is it possible to print in the same line from right to left in Crossterm

I try to print a couple of words from right to left but my last word overwrite previous and erase line to the end. I got in my output just Second word, What I'm

How to fix Rust diesel cli link libpq.lib error on install

I'm trying (for hours now) to install the cargo crate diesel_cli for postgres. However, every time I run the recommended cargo command: cargo install diesel_cli

OpenGL texture arrays render the texture completely black

I'm attempting to render a .png image as a texture. However, all that is being rendered is a black square. Can anybody see any mistakes in my OpenGL GL_TEXTU

How to reuse Tokio runtime in Rust FFI library

I want to write a FFI wrapper for sn_api library, which contains async functions. It will be used in single-threaded non-async code written in Red. I found, tha

How to call contract's method from crate

I need to call the contract's method from my Indexer. Now I use tokio::process and near-cli written on NodeJs. It looks soundless, and I would like to do that f

Perform checks on a nested enum

I have an enum which is defined as follows: enum MyEnum { X(u32), Y(Vec<MyEnum>), Z(Vec<MyEnum>), } As you can see, the enum is nested

How to iterate over a vector without moving it

I have a recursive type which doesn't implement copy struct Node { board: Board, children: Option<Vec<Node>>, } I have a Vector of these no

Using clap 3 derive macros, how do I specify that at least one argument of a group must be present?

I have a clap struct as follows: #[derive(Clap)] #[clap( version = "0.1.0", author = "..." )] pub struct Cli { #[clap(long)] arg_a: Option<St

How can I deserialize a type where all the fields are default values as a None instead?

I have to deserialize JSON blobs where in some places the absence of an entire object is encoded as an object with the same structure but all of its fields set