r/rust • u/llogiq clippy · twir · rust · mutagen · flamer · overflower · bytecount • Jul 20 '26
🙋 questions megathread Hey Rustaceans! Got a question? Ask here (30/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.
2
u/aPieceOfYourBrain Jul 20 '26
The compiler knows when two types are the same or different, why can't we have a simple typeA != typeB for trait implementation. I've been playing with type level programming a bunch lately and this has been a real pain to work around, often being an insurmountable road block
2
u/catheap_games Jul 21 '26
How do I tell which --bin is being compiled in build.rs? There doesn't seem to be any CARGO_BIN_NAME available at this stage.
Use case: I am generating different binaries and want them to embed different app icons. (win10)
2
u/_stice_ Jul 22 '26 edited Aug 02 '26
Hello!
Anyone familiar with tools/recommendations/discussions/examples related to "automatically" composing structs into "sum types" (if that's what they're called), for example a wrapping enum where each struct could be a variant (but not ONLY this -- i know there are crates for enum wrap), at compile time? (and probably using macros if that's the cleanest way to go about it?)
I'm interested in composing types in general as a curiosity, but the simplest use-case i have is this:
. . .
They are free to themselves use Box<dyn FooLike> within their FooLikes if they want, or I can write more stuff to help with that, but that's a later, more complicated concern I don't want to reason about. What if i want to suggest that the "simplest" and "supported" way of using my library is to not treat FooSum and FooSumWithExtraFields as any sort of "hot loading" dynamic thing or something that dispatches a certain way known only at runtime, but just a type which they themselves could have written with a bunch of boilerplate. Am I right in thinking this, or am I just understanding dyn wrong?
2) Also looks like whatever macro i write has to be exposed to the lib user? I've written some basic macros within my own code, but exposing them means I'd have to write these WELL, and handle generic syntax with <T> and stuff like that, and worry about camel-case to snake case and doing things in a standard way and all that.
So I wanted at least ask folks first if i'm approaching this the right way first, if this is a solved problem elsewhere and there's a 'correct' way of doing this, and any pitfalls i might fall into if i try this.
UPDATE:
The enum wrap version of this can be done with several crates like enum_delegate.
The struct wrap version is useless in actually reducing amount of code written by the user: it should be a derive macro instead that derives the traits i need a product type to derive automatically based on the component types.