Category "rust"

How Can I Hash By A Raw Pointer?

I want to create a function that provides a two step write and commit, like so: // Omitting locking for brevity struct States { commited_state: u64, //

Create macro to simplify declaration of deeply nested enum?

I want to use deeply nested enums to represent blocks in my game: enum Element { Void, Materal(Material) } enum Material { Gas(Gas), NonGas(NonGas) } enum NonGa

Check 2 keys for Vacant

I am using the HashMap to store some of the value. Now I want to check whether HashMap contains keys, if not insert data else return HashMap is not empty. Below

Explicit lifetime annotations toy example

I'm trying to figure out a Rust lifetime issue and after boiling it down a bunch, I realized that I have no idea how I would explicitly annotate the lifetimes o

Lifetime on a single argument function

I've read the Rust Book and some other tutorials on lifetimes. I thought I was understanding lifetimes as like a generic parameter that a function takes, and th

Rust generic value memory store implementation

I am working on an API for an object store, and I am struggling to figure out a way to implement it in Rust. It is a bit frustrating, since I have a good idea o

Path always returning false when trying to manually put a path with Rust

I've been learning Rust, and I'm having a bit of a problem with this code. let path = Path::new(&return_path); // return path is the user input println!("{

Rust - return a future in a closure

I am trying to add a return type of a future in a closure. But the compiler is telling me that `impl Trait` only allowed in function and inherent method return

Deserializing adjacently tagged data with special characters

I have JSON data that I need to deserialize, where the format is [ { "tag": "path\like\string", "data": [{"fieldA": 1}, {"fieldA": 2}] }, { "t

Rust throws an error when running code with OpenCL

I do not know rust at all, but I know a little C / C ++, tell me why this code causes an error? I just copy/paste it use std::fs; use std::ffi::{CString}; use o

cargo build-bpf fails on ubuntu

rustc --version = rustc 1.60.0 (7737e0b5c 2022-04-04) solana --version = solana-cli 1.10.8 (src:623ac656; feat:1122441720) npm --version = 8.5.1 node --version

Additive deserializing with Serde

I'd like to additively deserialize multiple files over the same data structure, where "additively" means that each new file deserializes by overwriting the fiel

In Rust, what happens if main function returns Err?

According to The Rust Reference, If a main function is present, (snip), and its return type must be one of the following: () Result<(), E> where E: Erro

How do I allocate space for elements in vector for type T?

fn test<T>(arr: &mut [T]) { let vector=vec![] //what can I do here so that I have vector as vec with same size as arr and of type T. } fn main(

String allocation behaving strangely

This compiles fine (from the rust lang book): fn main() { let mut s = String::from("hello"); s.push_str(", world"); println!("{}", s); } This does

Error obtained in rsmpi using MPI_Gather function

I a writing a simple code for MPI Gather, but I am getting the error: An error occurred in MPI_Gather reported by process [1154023425,0] on communicator MPI_COM

Error obtained in rsmpi using MPI_Gather function

I a writing a simple code for MPI Gather, but I am getting the error: An error occurred in MPI_Gather reported by process [1154023425,0] on communicator MPI_COM

What will match ergonomics do when encounters reference pattern?

I have read the rfc 2005, knowing the process of manipulation is a repeated operation. And I say encounters reference pattern, I am not talking about encounteri

Patch a transient git dependency to a specific rev

I depend on crates a and b, where I patched b to a git dependency on ref foo: # Cargo.toml of my crate [dependencies] a = "1.0.0" b = "1.0.0" [patch.crates-io]

Rust MongoDB set unique fields

How to set a unique field in the mongodb rust implementation? Are you supposed to use create_index()? async fn create_id_fields(client: Client) -> Result {