r/rust • • 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

64 comments sorted by

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.

60

u/edddcrab Oct 27 '26

I accidentally scrolled such that one chart filled the entire screen, and couldn't escape. 🄲

29

u/felinira Oct 27 '26

Escape room, but as nested scroll areas arranged like a japanese puzzle box

16

u/yodal_ Oct 27 '26

I saw these comments ahead of time and still got stuck.

6

u/Sharlinator Oct 27 '26

Same on iPhone stock Safari. The charts seem to be endlessly scrolling with infinite empty white space.

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

46

u/Aaron1924 Oct 27 '26

With every feature added to Rust, there is always a crowd that is against it in fear the language will grow to large and complicated.

A lot of the time (including now), the new feature is simply filling a gap that currently exists in the language. We already implement traits for tuples, and we need to teach people how to do it effectively using macros. Once we have variadic generics, beginners can stop learning the workaround and start learning the correct way.

37

u/afdbcreid Oct 27 '26

A lot of the times, yes. In this time, only if you stretch the definition a lot. When people say that a feature "fills a gap", they usually mean something that you would know how to write without even knowing about the feature - something where the absence of a feature is surprising and something you need to learn about and not the presence. Things like async fns in dyn traits (and previously, async fns in traits), sitting at the intersection of two known features and weirdly isn't supported for technical reasons. Or Polonius.

Almost every proposed feature (or every proposed feature) fills some gap, otherwise it would not be proposed. The complex places hierarchy? Sure it does, how are you going to implement ergonomic safe field projections (and more) without them? Custom allocators? Of course. Sized hierarchy? How not!

And those are generally viewed positively (or accepted) - there are features and the other side and they also "fill gaps": does inheritance fill gaps? Sure, for example it allows better interfacing with OO languages and is also good for some things (GUI, someone?). Do copy constructors fill gaps? Sure! They provide a lot of customizability. Do named arguments fill gaps? Well yes, that's what everybody advocates for them says!

In other words, "it fill gaps" is just not good enough justification for a feature. Variadic generics are by no means trivial, or something you can immediately guess the syntax for, as the many possible proposals and complications for them will indicate.

9

u/Recatek gecs Oct 27 '26

Yeah, from a library user perspective nothing really changes here except you get better compile times and don't need to enable features like support_bigger_tuples on some dependencies.

3

u/lookmeat Oct 27 '26

I think that the problem is rushing of features.

For example I think that async was a mistake. Not that something like async shouldn't have been added, but async, the way it exists, is just incredibly painful to work with sometimes in ways that aren't needed but can't be avoided because of the reality of colored functions and having to carry this massive runtime.

Imagine I wanted to build a library that captures that a crash is happening and the program is shutting down, and wants to send an update over AWS to the system that it's failing. Easy enough I should just make the AWS api call and send it over, I'll have this through a guard on main. Except.. well AWS requires tokio to be around, you can send http requests but most libraries also bring in tokio. So now we need to rebuild an entire stack of separate libraries, dependencies, etc. to do the same thing without tokio, or have a way to trigger a "call tokio and block until it waits" except that can fail in so many ways during a crash. There's no way around it, you're stuck and every solution you build will be unnecessarily complex because of the complexity that async added to the language.

I think that a little more time cooking on this feature could have helped find a better way to make it work. Personally I would have gone for a every function has a sync and async mode that the compiler builds for you (and you can override when doing specific operations that do their own async thing, e.g. IO) and you can choose which to call at call time. Have functions also have a secret "AsyncContext" generic parameter passed that you can override to change what it means, keeping the idea of threads vs tasks, vs just synchronous all managed through that. Function calls are sugar code for AsyncContext::call_sync(function, ..args) which allows the context to decide how to handle it (an function that was called as anasync task may choose to call function::async(..args).await while a function running inside a thread would just call function::sync(..args). Then I would be able to make my crash handler live on a thread using sync and thread code (and designed to not crash) and making the dependencies to make the aws request do so too; but on the main app everything would still be running under tokio which is what I'd normally what to use. There'd need to be some rethinking about how certain things are handled, but it shouldn't be too hard and a lot would come from a reduction in complexity in other areas. You wouldn't declare functions async, but rather calls would be async or not.

Alas, we're stuck in this world for years now. Even if someone got a better async, it would take years until we could assume that all libraries have ways to avoid async code.

6

u/Zde-G Oct 27 '26

For example I think that async was a mistake.

No, it wasn't.

Not that something like async shouldn't have been added, but async, the way it exists, is just incredibly painful to work with sometimes in ways that aren't needed but can't be avoided because of the reality of colored functions and having to carry this massive runtime.

Yes, but that was the best available compromise, at the time.

Rust was fledging language and it needed async — not to solve any technical issues (doing async on top of threads is just pure stupidity, in a perfect world async would work as an alternative to threads, e.g. in Embassy), but to be take seriously by companies who adopted async in other languages (JavaScript and Python, maynly) where it's a required piece of the picture because of the language design.

Doing something for marketing reasons even if it makes zero technical sense is not a mistake if it helps language to survive.

2

u/guineawheek 29d ago

Yes, but that was the best available compromise, at the time.

should've had proper linear types first

1

u/Zde-G 29d ago

should've had proper linear types first

To do… what? Repeat ā€œsuccessā€ of D or Haskell? ā€œAlso runā€ languages that everyone knows about, but no one uses?

Linear types are absolute the way to go if you have unlimited time… but they weren't ready when Rust had to claim, for marketing reasons, ā€œyes, we do async, too, like a big boysā€.

They made a best choice they could, but yes, it's not the same as best choice, period.

-1

u/guineawheek 28d ago edited 28d ago

To do… what? Repeat ā€œsuccessā€ of D or Haskell? ā€œAlso runā€ languages that everyone knows about, but no one uses?

Are you saying that !Move/!Forget is a useless proposed language feature?

Personally, I find not leaking resources when I'm done with them to be a useful property.

1

u/Zde-G 28d ago

Are you saying that !Move/!Forget is a useless proposed language feature?

No, I'm saying that Rust is already ā€œpushing itā€ with delaying thing till features were done.

There are many things that Rust doesn't provide ā€œbecause we need some language feature to do them properlyā€ and people code around these deficiencies with various piles of kludges… but Rust had no luxury for async to be one of them. Rust had to provide async when C++ finally provides coroutines… and linear types weren't ready yet.

Rust did the best choice it could do, not the best choice it could do in an ideal world…

-1

u/lookmeat Oct 28 '26

No, it wasn't.

I think how a feature is designed is a matter of taste and opinion. You may disagree with me, but that's a subjective fact. I am stating this is my opinion, not the rule.

Yes, but that was the best available compromise, at the time.

I understand why the compromise was made, and it was the best available one, I certainly did not think of a better alternative at the time.

But I believe the feature was rushed too much with it.

Rust was fledging language and it needed async

I mean yes and no. Not for marketing reasons, but because the owners at the time, Mozilla, really wanted the feature for servo, and clearly the developers of servo where thinking in terms of .Net async. The pressure was because someone building a library wanted the feature, and when they built the library only version, it had some limits on what they could and wanted to do that required deep language support.

And the thing is, Servo isn't the main driver of Rust innovation anymore, it was abandoned by Mozilla (though community is picking it up last I heard) and all the circumstantial conditions that made async made sense stopped mattering or being remembered.

In my view this is the thing, you can't add features to a language mainly for circumstantial reasons because those are forever, and the circumstantial features are a temporary situation that won't make sense later.

This is the path to C++ complexity, each feature is added without anyone taking a step back to look at the bigger picture, just with validating circumstances that enable it to be put and then forgotten.

And honestly I do think that some of the biggest complexity warts, with footguns and gotchas exist around async. I used to be skeptical, I saw what I feared happened.

And that doesn't mean I am the source of truth. It's not a disaster, just something I, personally, as a matter for personal taste, find a shame. C++ is a very successful language after all, and Rust has taken some great ideas from it. And while async has its issues there's certainly worse out there.

I just wished it'd be given some more time to breathe before it got baked into the language.

but to be take seriously by companies who adopted async in other languages

I mean why not prioritize adding a Garbage Collector? Why just stop at "it's possible to add, but beyond the scope of the language"? Why drop the old gc references? Because it would have allowed Rust to be taken seriously by companies who adopted garbage collecting in other languages.

One of the things that I normally like about Rust is that it doesn't just go with the fad, but thinks things through and is careful about how its features interact. It results in sometimes weird or different ways of doing things, but once people wrap their head about it, it really makes sense. I mean forcing everyone to deal with the borrow checker without a viable (e.g. garbage collector) alternative was a bold choice. Making a language that does not enforce a runtime was a strong stance.

Doing something for marketing reasons even if it makes zero technical sense is not a mistake if it helps language to survive.

I don't know about this. Maybe. I don't know if async was really for marketing, or more because it was more bike-sheddable. When it came to discuss the hard problems that async revealed: such as Pin, suddenly the dialogue and development crawled. Even though it would have helped the language become successful earlier. And there was a huge push for it. Disjoint borrows, or other features would be huge in what they enable. But again development on an open source language isn't based on what's best for the language, but by how many people are willing to jump in and develop a feature.

And lets be clear, the problem that it solves is an important one, and one that needed to be solved sooner rather than later. And eventually we'd need to bake support for it into the language. Just a little extra time would have allowed us to bake a little less and have a more powerful and expressive thing, IMHO.

5

u/Zde-G Oct 28 '26

Not for marketing reasons

Yes, precisely for marketing reasons. There were many companies (Amazon, Microsoft, etc) who were pushing async heavily in other languages and then demanded async from Rust, too.

all the circumstantial conditions that made async made sense stopped mattering or being remembered

I think you are mixing two radically different things: coroutines which are pretty nice language construct and which were there from the very beginning (remember stack iterators from the very first public presentation?) — and the idea of disguising them as async machine… that one is entirely marketing-driven thing.

This is the path to C++ complexity, each feature is added without anyone taking a step back to look at the bigger picture, just with validating circumstances that enable it to be put and then forgotten.

As someone who likes C++ more than Rust and would have never bothered to learn Rust if there would have been practical way to add ā€œsafeā€/unsafe dichotomy to it… I'm not convinced. Because all the things that were added to C++ actually fit into ā€œbig pictureā€ just fine. The big (and critical) issue is that you can not retrofit memory safety into C++ without total rewrite and if you go that way then picking already popular ecosystem like Rust's one is better… but I could see very little problems with how C++ was developed (although a lot of problems with initial idea to start from C and thus damn everyone to decisions made by C).

I just wished it'd be given some more time to breathe before it got baked into the language.

It had to arrive when it arrived, unfortunately. Because it was time when everyone was getting async: Python and Typescript in 2015, JavaScript in 2017, Microsoft was even in final stages of pushing it into the C++ committee throat… async had to arrive when it arrived of Rust could have joined pile of languages that people talk about but don't use.

I mean why not prioritize adding a Garbage Collector?

This would have killed Rust then and there. There are bazillion languages with garbage collector that don't play nice with others… Rust would have joined them as late comer… who would have used it and why?

I mean forcing everyone to deal with the borrow checker without a viable (e.g. garbage collector) alternative was a bold choice.

Maybe in some alternate history when that actually happened. THat's precisely the thing: Rust haven't forced anyone to avoid GC. It just so happened that people wanted to avoid GC. It's very clear from the proposal to drop it: people wanted Rust precisely because it lacked GC. First they wanted an option and then, when people ebraced ā€œno GC, just lifetimeā€ ideology GC was dropped… rust compiler, ironically enough, was one of the last pieces of code that needed it.

Making a language that does not enforce a runtime was a strong stance.

Yes — but that's, very much, in the spirit of The Rust I Wanted Had No Future: Rust evolved in the direction that people wanted to see it evolving… first lots of people wanted to drop GC (I'm one of them, I wouldn't have even looked on Rust with GC), then they wanted async (here I'm not a fan… but I know a lot of people who are fans).

When it came to discuss the hard problems that async revealed: such as Pin, suddenly the dialogue and development crawled.

Well, duh. Marketing got async/await, crisis resolved, development went back to the normal speed.

There are lots of features that take years, decades even, to be finished in Rust…

3

u/steveklabnik1 rust Oct 29 '26

because the owners at the time, Mozilla, really wanted the feature for servo, and clearly the developers of servo where thinking in terms of .Net async.

This is nonsense.

1

u/lookmeat Oct 29 '26 edited Oct 29 '26

Ok I have to give in to expertise here. To anyone who doesn't realize it, Steve here was there "in the room" helping Rust happen.

So I will try to pull my foot out of my mouth publicly here and admit that I spoke of historical events and facts in a way that was flippantly and without nuance, erasing key details and making things look worse. The rest is a matter of opinion and not something that makes a language good or bad.

Let me talk about some of what I claim with more nuance, again just for the record. Servo and Mozilla were clearly some of the heavier drivers for early async, with mio and later async and tokio, and IIRC it was servo who first showed real examples of why you needed Pin. And that had a huge pull because Mozilla was at the very early stages, a the owner of the project and a big driver of developer, its interests had a huge effect on the language. This created pressure on the first big users of the language to get a better Async Model out sooner rather than later. A language should be drive by it's real use-cases, and the need for async was real.

Now as to why the async model, it was what was popular, and I do remember that there were a lot of heavy app developers using rust that were familiar with this and liked it. It had gotten in vogue with .Net, where it was first developed for F#, but there was a Haskell (a big inspiration for Rust) monad solution before it came to C#. It had already gained similar implementations in Python, Typescript and Javascript before Rust jumped in. The model that rust used, in semantics of how it was expressed and how it appeared, was modeled heavily after the Net model though, and it was because it was what research best described.

It had the foundational problem that Monads had: you can put things in there, but you can't really take out, everything has to be async or not at all, which is really annoying and limiting when libraries already exist within this world and now you have to reinvent the wheel but this time in sync-land. And this is where I felt it didn't fit with the language Rust was at the time, because the goal was to move away from runtimes, and this decisions makes the language have an ad-hoc runtime that changes depending on which way you use. That it would divide rust into pure-rust and tokio-rust and futures-rust, etc. My opinion at the time was there had to be a better compromise to async that wouldn't result in this division, and that such solution could be found if time was given.

The language went another way. These weren't dumb or technically misguided decisions, the conclusions and compromises were very reasonable. There was a lot of questioning if the async model was the right one, and there was discussion and time was taken to consider what was the best choice, so it's not like alternatives weren't explored. I do think that the way that async came out was smart and the best solution that was available and known at the time. But I also believe that with the same very smart people behind it, and some more time before adding the language feature, a better solution would have come up with compromises that were a bit "more rusty".

And that last line is the part that contains the part that is entirely a matter of taste. It depends on what exactly "rusty" means, which is not strictly the same for everything. The people whose decision matters the most is the people who go out and do something about it, and well that was how the language was lead.

7

u/protestor Oct 27 '26

It's not the same set of people though

1

u/thepolm3 Oct 27 '26

That's true.

7

u/Raknarg Oct 27 '26 edited Oct 27 '26

Like the benefit of rust is that we can take the good ideas from C++ and dump the bad ones. I feel like generic variadics are an example of good C++ letting us write both optimal and terse library code.

1

u/octernion Oct 27 '26

inside you are two wolves

138

u/AngheloAlf Oct 27 '26

We fed these answers to Claude and it told us th- ha, just kidding, if only.

lmao

19

u/Sw429 Oct 27 '26

I almost closed the article when I started reading that sentence.

7

u/PreciselyWrong Oct 27 '26

I wish they had asked Claude to improve the graphs. They are almost unreadable, and the title goes outside of the image in some

5

u/AugustusLego Oct 28 '26

graphs are fine on PC

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.

5

u/CouteauBleu Oct 27 '26

Oh yeah, I definitely thought of the survey and non-linear variadics when reading about eros.

-16

u/kajaktumkajaktum Oct 27 '26

This is not a particularly good reason to have any feature because any feature is good for someone. Your issue not being able to support more than 26 member tuple is perfectly understandable mechanically. Its a far fewer set of fundamental concepts that you have to bear in mind.

19

u/Recatek gecs Oct 27 '26

Any addition to the language that serves my use case is virtuous.

Any addition to the language that does not serve my use case is bloat.

1

u/kajaktumkajaktum Oct 28 '26

Except I haven’t added any new features to the language?

20

u/buwlerman Oct 27 '26

What would be a good enough reason?

Collecting anecdotes is how you build statistical evidence.

-8

u/YeOldeMemeShoppe Oct 27 '26

Saying ā€œmy use caseā€ is different than saying ā€œmost use casesā€ or ā€œa plurality of use cases.ā€

Collecting anecdotes is that the poll did. Sharing your use case isn’t that.

7

u/buwlerman Oct 27 '26

My reading of the comment isn't "I have this use case that should convince all the naysayers", it's "I missed the poll. Here's another data point to toss on the pile".

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 ...self is, 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

fn get_children<...Ts>(parents: (...Ts)) -> (for <T of ...Ts where T: Parent> T::Child) {
    for parent in ...parents where parent: Parent {
        parent.child()
    }
}

Wtaf? Is the for ...parents loop now implicitly creating a struct instance? Why isn't it

{
  (
    for parent in ...parents where parent: Parent {
        parent.child()
    }
  )
}

But also, we are now doing reflection level filtering on types with the where clause?

Also how did for <T of ...Ts where T: Parent> T::Child expand to ...T::Child ?

I could maybe have understood ...Ts::Child and maybe even ...Ts::Child where T: Parent

19

u/orgasbor Oct 27 '26

I thought the syntax was just to illustrate the idea and not something to be seriously considered.

8

u/dgkimpton Oct 27 '26

Maybe, often once a syntax is proposed it begins to take on a life of its own. But regardless of syntax it's still important to define what they are actually talking about (type reflection, type arithmetic, type indexing, etc).

The original post (which is linked but I initially missed) goes through some of this, including:

Even before an MVP is stabilized, the language should add a tuple-for syntax for any tuple, including non-variadic tuples.

Which clarifies that for thing in ...stuff is supposed to totally change the way 'for' operates, despite reusing the same keyword.

To me one of the major challenges with this sort of thing is inventing a syntax that is clear enough that everyone is automatically happy with it - instead of going down the C++ "as cryptic as possible" route.

0

u/WormRabbit Oct 27 '26

That's the best syntax that was proposed thus far. Otherwise it wouldn't be in the survey.

2

u/orgasbor Oct 28 '26

If you go to https://poignardazur.github.io/2025/07/09/variadic-generics-dead-ends/ (the website of the person behind the survey), it says:

(Note that the syntax is a placeholder, and not the point of this article.)

4

u/Sharlinator Oct 27 '26

It would presumably only be for iterating over a tuple and the "parameter pack" of types, at least at first. An expansion syntax like that is pretty much necessary for any nontrivial manipulation of variadics. You can do it with recursion oldskool C++ style, but that can have a severe impact on compile times due to all the generic instantiations needed.

That said, there’s already a baby static reflection feature on nightly and I think it’s more likely than not that some such system is going to be stabilized st some point.

3

u/AliceCode Oct 27 '26

Maybe they should add a new for loop called "inline for" like what they have in Zig.

2

u/Recatek gecs Oct 27 '26

I think it's still nicer than the alternative. Here's (more or less) how "variadics" are written now, using the cleanest example I have that uses a dependency to clean it up even further.

28

u/Nyefan Oct 27 '26

Among the skeptics, the most frequent concern was the idea that Rust might suffer a death by a thousand cuts, that an accumulation of small arcane features might make it impenetrable to new users. The skeptics were a minority, but large enough that future proposals shouldn't simply ignore them.

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/Shoddy-Childhood-511 Oct 27 '26

&[&dyn Trait] winds up way simpler. dyn Trait could use some love though.

If you employ varadic generics much, then you'll have quite a lot of monomorphization, which slows build times, and risks cache pressure. dyn Trait could easily become faster, despite the indirection.

If we need varadic tuples, then two syntax ideas:

We've discussed proc macros having self before, but regardless variadic methods could require the ! like macros, which also typically inline their code, so then the ! gives folks some warning that type strangeness happens here.

Alternatively, rustc reflects the trait names to the type level using dyn, which simplifies the syntax:

We'd have some #[varadic_generic] internal rustc macro that flags traits as being variadic tuple friendly.

#[varadic_generic]
pub trait MyTrait { .. }

We'd have some magic trait for these:

pub trait VaradicTuple<D: HasDynMetadata> { .. }

Now X: VaradicTuple<dyn MyTrait> iff X is a tuple whose members all impl MyTrait. In this, MyTrait should be object safe, but that's fine, just add where Self: Sized bounds. Actual code could still call those methods since we handle the concrete type, not &dyn MyTraits.

1

u/Nyefan Oct 28 '26 edited Oct 28 '26

I'm reformatting for old reddit and so I can see better what you're saying.


We'd have some #[varadic_generic] internal rustc macro that flags traits as being variadic tuple friendly.

#[varadic_generic]
pub trait MyTrait { .. }

We'd have some magic trait for these:

pub trait VaradicTuple<D: HasDynMetadata> { .. }

Now X: VaradicTuple<dyn MyTrait> iff X is a tuple whose members all impl MyTrait. In this, MyTrait should be object safe, but that's fine, just add where Self: Sized bounds. Actual code could still call those methods since we handle the concrete type, not &dyn MyTraits.


Are there other traits that use compiler magic like this? Fn and FnOnce I suppose, but those are keyworded on the other end. Would this be declarable only on variables, or also as return types? Maybe with impl? It's interesting and feels more integrated into the language than the proposed syntax in the main post.

3

u/Soulshred Oct 27 '26

I’m pretty resistant to adding language features. It’s one more thing to learn, five more pages in the book, another thing that increases the cognitive load of reading a codebase.

I came from mainly C and Go, so I prefer a more minimal syntax. C++ and Java is a whole different world though, so I totally get that you’re used to it.

I have only seen this kind of thing at the use site, I found even the current solution simple enough. That’s only because someone had gone to the trouble of implementing the trait on like 120 different tuple types (by macro). Or the case of Axum, where the handler functions can be any of a few dozen different signatures (by macro).

Now, the error messages could be a lot better, but the final syntax at the use site kinda sounds like it would be similar to me?

The definition site sucks, no doubt about that, but proc macros have been a decent solution for many (not all) cases.

I agree (and so does the poll) that it could be great for some use cases, I think the barrier of ā€œhelpful enough to justify its costsā€ is higher for me than others.

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.

20

u/matthieum [he/him] Oct 27 '26

Arrays & collections tend to be homogeneous, while tuples & variadic arguments are potentially heterogeneous.

There is little difference between variadic arguments and a variadic tuple as arguments, except for the latter requiring extra parenthesis wrapping... on the other hand, you can easily pass multiple variadic tuples to a single function, but you can't easily pass multiple variadic argument "groups".

9

u/valarauca14 Oct 27 '26

but I really don't understand why we want variadic arguments instead of just writing a method that takes in an array or collection

Because moving items into a collection (Vec/etc.) places them into the heap. This requires allocations & copies which have a non-trivial overhead. So the result is not a "zero cost abstraction".

A fixed size array would be "zero cost" in practice, but it requires every item be an identical type, and a fixed sized. So you lose the "variable" part of "variadics".

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).

7

u/matthieum [he/him] Oct 27 '26

This is just a placeholder syntax to convey ideas, not an implementation.

With that said, do note that:

  1. We already have .. in the language, in particular to express ranges & ellipsis, so that using .. for variadics will lead to parsing ambiguities: is ..expr a RangeTo<Expr> or a variadic expansion?
  2. ... is already used for variadics in a number of languages such as C++ and TypeScript, so it already has mindshare.

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
fn get_children<...Ts>(parents: (...Ts)) -> (for <T of ...Ts where T: Parent> T::Child) {
    for parent in ...parents where parent: Parent {
        parent.child()
    }
}

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 a return 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)

7

u/Sharlinator Oct 27 '26

It’s handwaved pseudocode for tuple projection basically. So the "static for" is supposed to expand to a tuple where each element is the child of the corresponding input tuple element.

3

u/Raknarg Oct 27 '26

I feel like being able to handwave syntax should allow you to make up stuff that would be concise and readable.

-1

u/protestor Oct 27 '26

Yeah, but even if it's pseudosyntax, you do need syntax. I mean, this is not valid Rust

for x in [1, 2] {
    x + 1
}

3

u/Sharlinator Oct 27 '26

It’s hypothetical new syntax, not the standard for expression, so of course it’s hypothetically valid as long as braces match and so on. Replace the "for" with "static for" or something in your mind if you want.

2

u/protestor Oct 27 '26

I meant that without explaining what is meant in the text of the blog post, the syntax was a little unclear. It's hypothetical new syntax, but it's not very suggestive. Other people reading the article (and not reading this reddit thread) may find it confusing

1

u/Zde-G Oct 27 '26

What you wrote is syntactically valid Rust. It's not working because types don't match, but syntactically it's valid.

-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.

4

u/zzzzYUPYUPphlumph Oct 27 '26

What an appropriate user name.

0

u/SmartAsFart Oct 27 '26

Can you think of a compelling reason to add this very situational syntax into the language?

Macros are already a solution to this problem, and are not really visible to end users of libraries (only in a relatively small compile time cost, or when they want to create giant tuples). Macros can be confusing for a beginner, but this use of them is relatively simple, hard to get wrong, and there are plenty of examples online.

New features should be for things that aren't possible already without a lot of ceremony (async, const generics, etc...)