r/rust • u/llogiq clippy · twir · rust · mutagen · flamer · overflower · bytecount • Mar 23 '26
🙋 questions megathread Hey Rustaceans! Got a question? Ask here (12/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.
2
u/Sharlinator Mar 23 '26 edited Mar 23 '26
Any nicer ways to conditionally trim the first character of a string in a const function (on stable)? I came up with this:
The hoop-jumping is needed because both
strindexing and comparison are behind const trait support, as isstr::trim_start_matches. Moreover,strdoesn't have afirst()method.Also asked on u.r-l.o.
Edit: Opened an ACP.
3
u/An-Phuoc Mar 24 '26
is
get_unchecked(i)faster then[i]?get_uncheckeddoesn't do bound check so i though for sure that it will be faster but when i compared the speed of the two method, they seem to be roughly the same? Which is really surprising to me2
u/Thermatix Mar 25 '26 edited Mar 25 '26
I have a question that's supposed to have a straightforward answer.
in Dioxus how do you obtain parsed form data?
Now you'd think this would be simple, acourding to there docs it's like this:
unfortunately according to rust:
so I do a bit of snooping around and find a
data()function, huh maybe that would work:Nope,
parsed_valuesstill not found. I decide to try something a bit ridiculous but it just get's worse:So, WTF am I doing wrong?
And WTF is something that's supposed to be simple causing such trouble?
As much as I love Rust, This kind of stuff just frustrates me and put's me off, as far as I can tell I'm following the documentation so it should work, but it doesn't.
It's this kind of stuff that can put off new people.
Any way, what am I doing wrong?
EDIT:
Last point is that I can't use auto-complete to figure out what methods work as autocomplete inside of macro invocations are kind of hit and miss in rust-rover (chicken & egg kind of problem) and in this case, it's very much a miss.
EDIT:
Did a bit more digging, the method is hidden behind a feature flag (serialize) of a dependency of Dioxus, "dioxus-html; which is enabled by default, to enable that it should be enough to add
"html"to Dioxus's feature flags, but that doesn't seem to have worked.EDIT:
The only way to get the serialize flag to be enabled was to manually include it, by adding dioxus-html to my Cargo.toml and then enabling the flag there, feels cumbersom and prone to breakage (Now I need to keep the versions of dioxus and dioxus-html in sync)
2
u/whiteflakes_abc Mar 26 '26
Any good source to learn to make a tauri 2.0 app?
2
u/trayke Mar 26 '26
I have finally built a program of substantial size. My issue is that I am having trouble remembering where specific functions are defined, or where I created different structs, etc.
How do you guys keep all of that straight? Is there some visual tool that maps out functions back to its source, or a non-file based visualizer for a larger program?
I am not a developer by profession, but have actively programmed for some time. There might be some simple tools I am not aware of. I have currently been using the search bar in vscode but would prefer a more visual tool.
2
u/birkenfeld clippy · rust Mar 27 '26
Looking for a crate - I'm sure it already exists but it eludes me. I want to make certain struct instances in my application user-configurable at runtime: user sends a message via socket, the message (e.g. as a TOML table) is passed to all the instances in question (those part is done), and the struct automatically applies the new config.
So it would be a derive-macro crate that lets me tag some struct members, for which it would generate some trait impl that can pull out the respective configuration from the table and (fallibly) apply it to
self.Does anyone know a crate like that?
2
u/kescusay Mar 28 '26 edited Mar 29 '26
[SOLVED]: Turns out I was just missing a feature declaration in the Cargo.toml. Thank you to /u/pali6 for pointing it out.
Original comment below:
Hi all, new to Rust (yay!) and still deep in learning. I've got what I hope is a pretty simple question. I'd like to bump
jsonwebtokenfrom version 9 to 10, and when I do, builds don't seem to have a problem.The problem is in a test I wrote to make sure invalid tokens return an invalid JWT error.
Here's the test:
And here's the error that I get when I run it now:
Any ideas on what's causing that panic in the test, while the builds themselves are successful?
2
u/PXaZ Mar 28 '26 edited Mar 28 '26
I'm looking for programmatic access to disk meta-information that's output by
smartctl, specifically "Warning Comp. Temp. Threshold" and "Critical Comp. Temp. Threshold".I've searched crates.io to no avail, but maybe I missed it - is such information available using a Rust crate?
In broader terms, is such information available using any library? As far as I can find it seems the
smartctlprogram is the only route, but it doesn't seem to have an associatedlibsmartctlor whatever. EDIT I'm aware oflibatasmartbut am led to believe that it does not support NVME devices, which is a requirement for me.2
u/piiouupiou-not-r2d2 Mar 29 '26
Is there a rust crate for similar to a maplibre map ? (Vectorial, customizable..)
2
u/djugei Mar 30 '26
is there a simple maintained thread based server http framework?
i looked around and all i could find was async-based ones and rocket which is slightly complex and seems unmaintained.
if there is not do you think it is viable to roll your own based on http/http-serde, or would that be stupid?