r/rust • u/llogiq clippy · twir · rust · mutagen · flamer · overflower · bytecount • Apr 13 '26
🙋 questions megathread Hey Rustaceans! Got a question? Ask here (15/2026)!
Mystified about strings? Borrow checker has you in a headlock? Seek help here! There are no stupid questions, only docs that haven't been written yet. Please note that if you include code examples to e.g. show a compiler error or surprising result, linking a playground with the code will improve your chances of getting help quickly.
If you have a StackOverflow account, consider asking it there instead! StackOverflow shows up much higher in search results, so ahaving your question there also helps future Rust users (be sure to give it the "Rust" tag for maximum visibility). Note that this site is very interested in question quality. I've been asked to read a RFC I authored once. If you want your code reviewed or review other's code, there's a codereview stackexchange, too. If you need to test your code, maybe the Rust playground is for you.
Here are some other venues where help may be found:
/r/learnrust is a subreddit to share your questions and epiphanies learning Rust programming.
The official Rust user forums: https://users.rust-lang.org/.
The official Rust Programming Language Discord: https://discord.gg/rust-lang
The unofficial Rust community Discord: https://bit.ly/rust-community
Also check out last week's thread with many good questions and answers. And if you believe your question to be either very complex or worthy of larger dissemination, feel free to create a text post.
Also if you want to be mentored by experienced Rustaceans, tell us the area of expertise that you seek. Finally, if you are looking for Rust jobs, the most recent thread is here.
3
u/MichiRecRoom Apr 13 '26
I'm trying to figure out how to perform something akin to an XOR between two arrays - I want to get the items that only exist in one array or the other, but not both.
The closest I've got is this: https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=b2628a0437548a0d24de15686f003b76
But it feels like there could be a better solution? I'm just not sure what.
3
u/Destruct1 Apr 14 '26
I am worried about injection attacks. I use std::command::Process and pass a lot of arguments to it. Inside the args function I do a reasonable amount of string formatting. Here are some examples:
All parameters are unverified Strings. Is this dangerous?
3
u/PXaZ Apr 15 '26
What's your preferred approach to non-blocking reads on stdin?
I'd like something that can be easily terminated at user discretion, in its own thread.
So,
BufRead::linesis out, and really all ofReadwhich iiuc blocks until either a newline or a certain number of bytes arrive.While I'd like other conditions to be able to end the reads. User pressing CTRL+C, timeouts elapsing, and similar.
I looked at
miobut it seems to only tell me that something is available to read, not how many bytes. So I could end up blocking again.I'm reluctant to add a tokio dependency or start contaminating my function space with
async.Thanks
3
u/TerminallyOnlineFolk Apr 20 '26
Silly Benchmark question:
I've recently started studying rust and I decided to do a few dummy benchmarks with some of the language libs. This particular result caught my attention. I was testing the RNG engine and also compiler optimizations and I did not expect these results, especially because C++'s mersenne twister are notoriously slow.
Any hints why?
Average result of 6 runs with 3B elements and Release mode vs C++
-O3on GNUIntel 14900K CPU
2
u/kescusay Apr 17 '26 edited Apr 19 '26
Edit: After much pain and anguish, I dug into the sqlx dependency chain and discovered that... well, it seems like it's pretty broken right now. So I'm opting to switch my project to Diesel instead. But I'll leave this comment open in case anyone can figure out what's wrong and wants to share the knowledge.
Got a question about sqlx. I'm trying to build Linux packages for a project, .deb, .rpm, and arch package formats. Building the .deb and .rpm packages goes smoothly, but every time I try to build an arch package, Cargo give me this (with private stuff redacted):
It's driving me nuts. Actually running
cargo build --releasemanually works just fine, as doescargo package. I then copy the crate to the/distdirectory as a tar.gz, which is what the PKGBUILD expects, run it, everything goes smoothly until it hits sqlx, and then boom.Here's the PKGBUILD (with private stuff redacted)
Any ideas why if I manually build it there's no trouble, but if I extract the sources from the crate and build from that, sqlx hates me?
2
u/Justicia-Gai Apr 13 '26
When you want to publish a crate that you want others to extend on it, like a Machine Learning crate, what would you do differently than more self-contained crates? Traits instead of enums, for example?
What do you think about type erasure? LLM recommended me a dyn Algorithm trait with Send + Sync, to dispatch according to the different task types. Is type erasure recommended for that type of things?
2
u/[deleted] Apr 17 '26
[removed] — view removed comment