43,908 questions
0
votes
0
answers
17
views
Implementation of the (modular) visitor design pattern
I am creating a QueryBuilder, so I though that it w'd be amazing to serialize objects to tokens, and have an AST within the QueryBuilder. So I immediatly though about the Visitor Design Pattern.
Here'...
0
votes
0
answers
19
views
Rust Iced Markdown View isn't Showing in the window
I've tried the rust iced framework and tried to create a markdown view from the documentation and the code compiles and renderes the windows but the code
pub fn new() -> Self {
Self {
...
0
votes
1
answer
37
views
What happens when I take in &str with AsRef<Path>?
I have the following implementation of to_file for a struct which takes a parameter with AsRef<Path>:
pub fn to_file(&self, path: impl AsRef<Path>) -> anyhow::Result<()> {
...
-2
votes
0
answers
29
views
Compiler complaining about nonsensical traits?
I was trying to compile some heavily generic code in a project. I am getting a top level error that makes no sense, in particular:
error[E0277]: the trait bound `S: linear_isomorphic::InnerSpace<S&...
1
vote
0
answers
46
views
How would I create a shared memory buffer to display animations using the Kitty Graphics Protocol in Rust?
I'm using Arch Linux with Wayland. My terminal is Kitty.
I'm trying to create an animation using the Kitty Graphics Protocol. However, I want this animation to cover the whole screen and run at 60 fps....
Best practices
0
votes
1
replies
40
views
Can I have a reference to a variable while still allowing that variable to be mutated in Rust?
Is there a way that I can have a reference to a variable while allowing that variable to be mutated in Rust, so long as I "pinky promise not to access the data of the stored variable" so ...
Best practices
0
votes
4
replies
39
views
In rust, is there an iterator adapter that can consume multiple (but not all) items before producing an output?
I can't help thinking this is not an uncommon idiom and I'm just being an idiot but I've spent ages searching SO and reading the docs for std::iter and for the itertools crate and have got nowhere. ...
-2
votes
1
answer
72
views
Why BufReader.read_line(&mut buf) reads all file content into buf? [duplicate]
I'm new learning rust and this is an issue with BufReader.read_line().
In the official documentation it says "This function will read bytes from the underlying stream until the newline delimiter (...
0
votes
0
answers
54
views
How to use std::vec::windows to look for a sequence with repeated elements removed
I have a list of elements in an array in which I'm looking for a sequence. Using std::vec::windows::any, I was able to confirm presence/absence of a given sequence. I'm facing an issue if there are ...
0
votes
0
answers
39
views
Why does `-fuse-ld=lld` when targeting `aarch64-unknown-linux-musl` cause the binary to dynamically-link the interpreter?
I've got a working Rust cross-compile setup on Arch Linux, targeting x86_64-unknown-linux-musl and aarch64-unknown-linux-musl from a x86_64 host.
By default, binaries for both targets are fully ...
6
votes
1
answer
191
views
Shared assembly between Rust and C using preprocessor
I am using Rust to target a baremetal system.
My startup code is written in Assembly and is in crt0.S, it is shared between Rust, C and Assembly projects.
crt0.S contains:
#include "constants.h&...
Best practices
0
votes
4
replies
73
views
Should I log errors from `tokio::task::JoinHandle::await` in a shutdown method?
I have a couple of shutdown methods looking like:
pub async fn shutdown(self) {
self.cancel.cancel();
let _ = self.join.await;
}
Should i ignore the value returned from join or ...
0
votes
1
answer
37
views
Rust Chumsky parser: () is not an iterator when folding repeated (BinOp, Expr)
I've been working on the 'multiplication / division and general expressions' portion of my parser in Rust complains that () is not an iterator when I try to fold over the repeated operator-expr pairs.
...
-4
votes
1
answer
36
views
How to fix Rust issue E0515 related to Tauri V2^ [duplicate]
I was working on my Tauri project when I came across this error when I ran npm run tauri dev :
error[E0515]: cannot return value referencing temporary value
--> src/main.rs:209:97
|
209 | ...
Best practices
0
votes
2
replies
93
views
Why CPU-Bound Work should not run on Tokio’s I/O Executor
Why is the blocking thread pool (spawn_blocking) better suited for CPU-heavy work than the I/O executor threads, even if my runtime has many worker threads?
In the example, both IO executor and CPU ...
0
votes
0
answers
34
views
Serializing complex data to flatbuffer multithreaded gives endless type errors
I'm working on a reasonably complex project that is using flatbuffers to serialize data to be used through FFI. The project incorporates several languages, but most of the heavy lifting, including ...
-3
votes
0
answers
61
views
Why is my Google Drive folder-tree reconstruction incorrect in Rust (Axum)? Some files show up missing or in wrong folders [closed]
I’m building a server in Rust using Axum where I need to generate a folder-tree structure of a user’s Google Drive. I fetch all files and folders for each connected Google account and then try to ...
Advice
0
votes
3
replies
61
views
Rust LLVM unit test coverage includes the test code itself
I wrote some Rust code and also wrote some test code in the tests submodule.
Then I run `cargo llvm-cov --open` to test. But it keeps saying that my code below has branch coverage completion.
#[test]
...
1
vote
1
answer
63
views
Make a custom rust class input to polars expression plugin
I want to make a custom polars plugin which takes a class defined in rust using pyo3. I have managed to create a class which can roundtrip pickle defined as:
#[pyclass(module = "mylib._internal&...
Advice
0
votes
1
replies
50
views
Axum streaming read yields poor performance
Hi I'm using axum as my rust HTTP server, which takes bytes and persist in my backend (you could think of it as S3).
The client side request is usually ~16MiB, so
- every time I received from server ...
1
vote
1
answer
86
views
Make newtype iterable (same as underlying)
I wanted to quickly make an alias type iterable in rust. Here's what I have:
#[derive(Debug, Clone)]
struct SSHDomains
{
hostname: String,
path: String,
}
#[derive(Iter, IntoIter)]
pub struct ...
3
votes
2
answers
83
views
How to specify -fPIC and -fPIE options when building Rust binaries
In GCC we can specify -fPIC option for shared library and -fPIE for executable to create code that can be executed at any memory address. How do I achieve the same in Rust using Cargo?
1
vote
0
answers
108
views
Why does curl in WSL2 (Fedora and updated Arch) return "Recv failure: Connection reset by peer" on https://sh.rustup.rs?
Problem Description
I am trying to install Rust through rustup in WSL2, but in some
distributions any curl request to https://sh.rustup.rs fails with a
TLS error.
Command:
curl --proto '=https' --...
-1
votes
0
answers
82
views
we get "NONE" in the page instead of the correct value even tho dbg! prints the correct value
so we read the cookie, to give it to the page,
#[get("/hub")]
fn hub(cookies: &CookieJar<'_>) -> Template {
let username = cookies
.get("username")
...
-4
votes
1
answer
45
views
How to install anchor in WSL via avm?
liam@my-pc:~$ avm install 0.30.0 --force
Updating git repository `https://github.com/coral-xyz/anchor`
warning: skipping duplicate package `swap` found at `/home/liam/.cargo/git/checkouts/...
1
vote
0
answers
70
views
How to get pass `wgpu::Buffers` to `CoreML` `predict` as inputs
I am have a wgpu::Buffer. I am trying to create input to a CoreML from this buffer.
let hal_buffer = unsafe { buffer.as_hal::<wgpu::hal::metal::Api>() };
let Some(hal_buffer) = ...
Advice
0
votes
2
replies
76
views
How can I tell the compiler I want a type to be of a certain shape and implement a trait in Rust?
Take this code:
pub struct Complex<T: SimdElement>(Simd<T, 2>) where Simd<T, 2>: StdFloat;
How would I express that I want the inner value to be of the same type as the trait bound?
...
4
votes
1
answer
105
views
How to disable logs from clap?
I have this code using clap:
#[derive(Parser, Debug)]
#[command(version = "1.0.0", about, long_about = "Long About")]
pub struct Args {
#[command(subcommand)]
commands: ...
3
votes
1
answer
67
views
Borrowed value does not live long enough for generic lifetime
The Rust compiler gives me a lifetime error with the following code (which is a minimal working example of some real code):
pub trait TElement: Copy {
// Details irrelevant
}
pub trait TSet<'a,...
Best practices
0
votes
0
replies
47
views
How should I pass user secrets from my frontend to my backend with Tauri?
I'm currently working on an app that stores secrets in an encrypted vault, and the key is derived from a user password. How can I securely prompt the user for their password? Is the IPC with invoke ...
0
votes
1
answer
62
views
How do I use rustyline::Editor::set_helper to react to tab-completion requests?
I'm going through Build your own shell, and I've got to the task of implementing command completion. A note suggests:
We recommend using a library like readline for your implementation. Most modern ...
0
votes
1
answer
78
views
Parallel processing of nested vectors
I have a vector of vectors a : Vec<Vec<usize> in Rust. The inner vectors Vec<usize> do not have the same size.
How can I apply a function in parallel to every usize element inside a Vec&...
-1
votes
0
answers
37
views
I have a problem with my rust pixels,winit script
I have error on line 87:
missing lifetime specifier
expected named lifetime parameterrustcClick for full compiler diagnostic
main.rs(87, 11): consider introducing a named lifetime parameter: `<'a&...
1
vote
0
answers
59
views
How to implement Gtk 4 Rust file drag and drop?
I have been trying to implement a simple drag and drop application in Gtk 4 Rust but I am unable to implement a working version. I can see connect_accept getting triggered, but no matter the result, ...
2
votes
3
answers
115
views
Dropping optional borrow in structure
I am writing a scripting language in rust, and I'm pretty new to the language.
When I compile source into byte code I move the compiled symbols (Chunk) out of the function.
I am also lazy and don't ...
0
votes
0
answers
83
views
trait bound error when using jsonref crate
I'm using jsonref crate which internally uses rustls crate. When compiling rustls crate it fails in QNX platform, but builds successfully in Linux platform. Below is the error message
Error
2025-11-...
3
votes
0
answers
79
views
Returning mutable references and lifetime in rust [duplicate]
I am trying to develop a linear algebra library in rust. So, as part of it I am writing code that iterates through a n-dimensional array and returns mutable references. It's like writing a view for a ...
Best practices
3
votes
9
replies
141
views
Calling associated fuction on a complex type
I want to write T::associated_function(..) but sometimes T is too verbose to write, like a long tuple.
Is there any way to avoid writing the full T?
pub trait Param {
fn encode_type(out: &mut ...
1
vote
1
answer
101
views
Rust cargo doesn't throw error for invalid search paths present in build.rs
I have a build.rs file in my project which contains code of library search paths and library linking. However, if I specify library search paths that doesn't exist in build.rs, it doesn't throw any ...
5
votes
2
answers
143
views
Rust global variable lifetime safety
This is a pattern I want to be able to use in my code to have global variables that contain non-static references. Is it memory safe? If not, how can I make it so?
use std::cell::Cell;
pub struct ...
1
vote
0
answers
54
views
How do I create a lazy asset loader in bevy?
I want to load assets from a custom zip-like format, or even GoldSrc WAD3 files.
My initial attempt was to use a custom AssetLoader, but I'm not feeling comfortable having to load the entire file's ...
2
votes
0
answers
159
views
Rust language server not working in neovim
I just started using neovim. I could get the lua language server to work but not the rust language server (rust-analyzer). When I open a rust file like hello.rs I get the error
LSP [rust_analyzer] ...
-3
votes
1
answer
85
views
How to deference JSON data references using jsonref crate
This is a follow up of my previous post. As suggested, I tried using jsonref crate to de-reference references present in a JSON file. Unfortunately, I'm not getting de-referenced output.
main.rs
use ...
1
vote
1
answer
134
views
How do I take a `Pin<Box<T>>` from a struct in a method that consumes that struct?
Let's say I've got a struct that contains a pinned pointer to a boxed T and is Drop:
struct S<T> {
t: Pin<Box<T>>,
}
impl<T> Drop for S<T> {
// ...
}
How do I ...
0
votes
0
answers
84
views
rdkafka::message::ToBytes is not implemented for `&str`
I am trying to write a Rust program which generates random FX data and sends it to a Kafka topic.
The code I have written so far is quite short. It does not currently compile.
use rdkafka;
use rand;
...
1
vote
1
answer
74
views
Rust generic type results in trait not found anymore
Rust newbie here.
The following code throws a compiler error:
#![feature(portable_simd)]
use std::simd::Simd;
use std::simd::SimdElement;
fn test_mul<T: SimdElement, const N: usize>(x: [T; N]) ...
Best practices
0
votes
1
replies
77
views
rust compilation profile check at build-time
tl;dr how do I get my project's build profile at build-time so I can branch on it?
I have a custom profile for my rust project called myprofile. My Cargo.toml has
[profile.myprofile]
I build the ...
1
vote
1
answer
101
views
Cause of AlignmentMismatch error while using bytemuck?
I'm facing an AlignmentMismatch error while trying to cast a Vec<u8> to Vec<T>, where T is a struct that uses repr(C) and Pod + Zeroable.
I've also tried the slice road &[u8] -> &...
5
votes
1
answer
147
views
Why can't I use reference parameters on methods within impls, that return an impl trait?
struct TestStruct { }
trait TestTrait { }
impl TestTrait for TestStruct { }
struct ResultStruct { }
trait ResultTrait {
fn make_struct(&self, str: &String) -> impl TestTrait;
fn ...
3
votes
1
answer
95
views
How to implement read trait? [duplicate]
I'm trying to work through Rust and using serde_yml as opposed to serde_yaml which has caused me much great confusion, and can't seem to find examples for parsing yaml from a file. I've been running ...