Category "rust"

Struct padding rules in Rust

Recently when I was learning Type Layout in Rust, I saw that struct in Rust supports the #[repr(C)] directive, so I want to to see the difference between the de

Rust build error: unknown `--json` option `future-incompat`

I am trying to build a basic application for the Adafruit CLUE using Rust. When using the peripheral access crate (PAC) everything works fine, but I would like

Is allowing library users to embed arbitrary data in your structures a correct usage of std::mem::transmute?

A library I'm working on stores various data structures in a graph-like manner. I'd like to let users store metadata ("annotations") in nodes, so they can retri

Set a project to use nightly by default

How do I set a Cargo project to build & run using nightly by default (i.e. cargo build is actually cargo +nightly build) without setting nightly as the glob

Classifying cubic bezier curves according to Loop & Blinn 2005

I am trying flatten a bezier path (remove all intersections and replace with end points) as part of the implementation of the rendering algori

Conways game of Life with 1D array

Right now I'm doing this tutorial for WebAssembly with Rust. The task is to implement Conways Game of Life in Rust. Writing a low-level language like Rust is ne

How to return the value of a reference field of a struct that is no longer used without copy?

Code like this: pub fn sample_from_categorical_logits(prob_logits: Tensor) -> (Tensor, Tensor) { let prob_obj = match prob_logits.size().len() {

Rust not printing to terminal

rustc is not outputting anything to terminal when using println!. Code: fn main() { println!("Hello, world!"); } Running it: me@mclaptop:~ > rustc he

Rust update mongo document

I'm trying to update my document, if I don't pass a field it is being deleted. my document is { "_id":"27fc47a4-0730-446c-8acd-41aa6e227406", "user_id":"a

How to build the docs.rs documentation of an FFI crate when the native library is not present?

I have a "sys" crate that links statically to a library: Cargo.toml: [package] links = "foo-1.0" build.rs: fn main() { println!("cargo:rustc-link-lib=d

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