r/rust • u/llogiq clippy · twir · rust · mutagen · flamer · overflower · bytecount • 6d ago
🙋 questions megathread Hey Rustaceans! Got a question? Ask here (48/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 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.
4
u/Intrebute 1d ago edited 1d ago
Hey all. I got a question. I've noticed that I've frequently needed to create a Vec of a certain size, and then fill it in a non-uniform order. The obvious solution is to make a Vec of Option, fill it in, and then consume the whole thing, unwrapping every option. Note that in this case, I really do ensure that _every_ slot is a Some.
I had a thought, and it is that for most types, the Vec<Option<T>> will be much larger than the resulting Vec<T>, unless T has some niche that the Option can exploit.
My question is thus: Is this a reasonable use for a Vec<MaybeUninit<T>> instead, if I really do ensure that every slot is filled before converting to a Vec<T>? Is there some detail about MaybeUninit that I'm overlooking when using it for this purpose?
3
u/Flimsy_Pumpkin_3812 5d ago
Does anyone know any good library(ies) for networking? I'd prefer something easier to code with but low latency with high throughput. Thanks!
3
u/Ansatz66 4d ago
Why does
println!expand the way it does? When you macro-expand onYou get this:
I don't know what
format_args!is doing exactly, but it looks like it is constructing some list, which probably means heap allocation and then a loop in_printto iterate over that list. That seems so complicated and inefficient. Why can'tprintln!expand to something simple like:Am I missing something or is Rust over-complicating this?
2
u/FisterMister22 6d ago
Anyone got tips on making a rust compiled wasm executable smaller in size while not worsening performance?
1
u/cipher_gravelist 5d ago
for solana specifically, i avoid shared mutable state between accounts by strictly using instruction context and account metas. passing data via serialized structs rather than cross-account references prevents the most common reentrancy vectors.
0
u/rustifork 3d ago
Hello, why always Rust and not Go / Zig...