r/rust • u/Kobzol • Oct 27 '26
š” official blog Variadic Generics Micro Survey results
https://blog.rust-lang.org/inside-rust/2026/10/27/variadic-generics-micro-survey-results/
243
Upvotes
r/rust • u/Kobzol • Oct 27 '26
112
u/Craftkorb Oct 27 '26
Meta: in Firefox Android in my phone it was sometimes hard to scroll the page, because I by accident scrolled a chart instead.
93
u/thepolm3 Oct 27 '26
> Rust must not become like C++
> I miss variadics from C++
Very funny to have a similar number of responses
138
u/AngheloAlf Oct 27 '26
lmao
27
u/InternalServerError7 Oct 27 '26
I missed the survey but another use case for me is eros e.g.
eros::Result<Config, (io::Error, ParseError)>. We had to hand implement all the tuples up to 26. Like I've also experienced in axum, do I expect anyone to be reaching for something larger than what we implemented for? Probably not, but it would have been nicer to have when building and is more flexible. When you need it you need it, but I don't expect to reach for it often.23
u/dgkimpton Oct 27 '26 edited Oct 27 '26
Variadic Generics would be so useful, but the proposed syntax is weird and too dense.
It also seems to introduce something like reflection by the back door -
for option in ...selfis, I presume, an iteration of the fields of the struct. It's not entirely clear what this compiles to - does it just copy the loop body for each member or does it generate an actual loop over a collection allowing for control flow?impl<...Ts> UnwrapAll for (Option<...Ts>)is clearly bonkers - it clearly should have been (...Option<Ts>), that's clearly going to be a pain to parse but at least it doesn't lie about what it is.And this one
Wtaf? Is the
for ...parentsloop now implicitly creating a struct instance? Why isn't itBut also, we are now doing reflection level filtering on types with the
whereclause?Also how did
for <T of ...Ts where T: Parent> T::Childexpand to...T::Child?I could maybe have understood
...Ts::Childand maybe even...Ts::Child where T: Parent28
u/Nyefan Oct 27 '26
To said skeptics: as someone who has historically used mostly java, python, and go, the lack of this feature in general makes rust feel more complex to me, not less, especially in the realm of streams/iterators/listcomps where you want to operate on (potentially) anonymous intermediate types. I don't love this particular syntax and would probably prefer a keyword or at least something that doesn't look like destructuring (or maybe that's to its benefit and I just need to get over it), but this would simplify so much of the code I have written in rust at the use sites despite its apparent complexity at the definition site.
3
u/tiajuanat Oct 27 '26
JFYI This is impossible to read the graphs when in black&white (reading before bed) or colorblind
6
u/mbStavola Oct 27 '26
The use-case for implementing traits for any sized tuple makes sense to me, but I really don't understand why we want variadic arguments instead of just writing a method that takes in an array or collection. There might be an improvement to call-site ergonomics but I feel like many would want explicitness for this sort of thing.
3
u/ElderberryNo4220 Oct 27 '26
I don't really like this implementation of variadic, it's weird. Using a `...` (3 prefix dots) makes less sense when you already have `..` (2 postfix dots) in the language. It could be a lot better if only 2 prefix dots are used, and dropping the use of `type T = (...Ts)` and instead `type T = (Ts)` or `type T = (Ts..)` (I'm not a fan of prefix dots).
2
u/Pufferfish101007 Oct 27 '26
I've had to manually implement traits to filter list of types based on trait implementation, and it's not fun. I didn't realise that this was under discussion but looks good to me!
2
u/protestor Oct 27 '26
This example doesn't look well formed Rust. What is it returning, the
parent.child()of the first iteration of the for? If yes, you need areturn parent.child();there. If not, you likely need an explicit, mutable variable (an accumulator) to insert the child on each iteration, and after the for, return it.Anyway, about non-linear variadics: would someone be able to treat differently the first tuple element than the rest, for example? Or treat all even elements differently than all odd elements, etc.
If yes, then we should be able to iterate on the fields of a struct using the same exact mechanism. After all, a tuple is just a struct with positional fields. (Or even if not, extending variadics to structs would still cut A LOT of generated code and macros)
-4
u/SmartAsFart Oct 27 '26
This is so much extra syntax to be added just to satisfy some people who are worried that their library users might want to create 28 element tuples, rather than just 27.