Skip to content

Commit 029cc6e

Browse files
committed
Add variadic generics survey
1 parent 5687310 commit 029cc6e

File tree

1 file changed

+145
-0
lines changed

1 file changed

+145
-0
lines changed
Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
# Survey questions
2+
3+
This survey is meant to both measure interest in variadic generics and gather data about how they might be used once implemented.
4+
5+
You can think of variadic generics as “being able to implement a trait for tuples with an arbitrary number of fields”.
6+
7+
Variadics in Rust might look like this (placeholder syntax):
8+
9+
```rust
10+
impl<...Ts: SomeTrait> SomeTrait for (...Ts) {
11+
fn do_stuff(&self) -> u32 {
12+
let mut sum = 0;
13+
for member in ...self {
14+
// The trait bounds ensure each member has a do_stuff() method
15+
sum += member.do_stuff();
16+
}
17+
sum
18+
}
19+
}
20+
21+
let value: u32 = (0, 0.5, "hello", Some("hello"), false).do_stuff();
22+
```
23+
24+
See [Analysing variadics, and how to add them to Rust](https://poignardazur.github.io/2021/01/30/variadic-generics/) for a full overview of features associated with variadic generics, and possible use-cases.
25+
26+
This survey is fully anonymous. The Rust survey team will go through the answers and release a summary on the Rust blog after the survey is complete. It's fairly short and should take less than 10 minutes to complete.
27+
28+
29+
### Have you heard about variadic generics before?
30+
31+
Type: select all that apply
32+
33+
- Yes, through Pre-RFCs and discussions on [`internals.rust-lang.org`](https://internals.rust-lang.org).
34+
- Yes, through discussions on Reddit.
35+
- Yes, through blog posts on [`poignardazur.github.io`](https://poignardazur.github.io/2025/07/09/variadic-generics-dead-ends/).
36+
- Yes, through other programming languages.
37+
- Yes, through other means: (open response)
38+
- No.
39+
40+
41+
### Are there cases where variadic generics would have made your project easier?
42+
43+
If you knew about variadics, are there cases where you've wanted them to be implemented in Rust?
44+
If you haven't heard about variadics before, are there cases where you've wanted to be able to iterate over lists of different types?
45+
46+
Type: select one
47+
48+
- Yes
49+
- No [`NEXT`](#variadic-type-mappings)
50+
51+
### Can you give more details about the project?
52+
53+
Please write a description of the project and what you would have needed variadics for.
54+
Be as detailed as you like, more detail is better.
55+
56+
Type: free text
57+
58+
59+
## Variadic type mappings
60+
61+
The following section refers to "mappings" of variadic generics.
62+
63+
In this context, variadic mappings refer to code that takes N-tuples of types as generic parameters, and refers to N-tuples of types derived from those parameters, where each type in the tuple is transformed in the same way.
64+
65+
For example:
66+
67+
```rust
68+
impl<...Ts> UnwrapAll for (Option<...Ts>) {
69+
type Unwrapped = (...Ts);
70+
fn unwrap_all(self) -> Self::Unwrapped {
71+
for option in ...self {
72+
option.unwrap()
73+
}
74+
}
75+
}
76+
77+
let my_gift_boxes = (Some(1), Some(true), Some("hello"));
78+
let opened_gifts = my_gift_boxes.unwrap_all();
79+
assert_eq!(opened_gifts, (1, true, "hello"));
80+
```
81+
82+
In that example, the trait `UnwrapAll` maps `u32, bool, &str` to `Option<u32>, Option<bool>, Option<&str>`.
83+
84+
### Are there cases where variadic mappings would have made your project easier?
85+
86+
Type: select one
87+
88+
- Yes (same project as above)
89+
- Yes (another project)
90+
- No [`NEXT`](#non-linear-variadic-generics)
91+
92+
### Can you give more details about the project?
93+
94+
Be as detailed as you like, more detail is better.
95+
96+
If it's the same project as before, you can include more details about how you would have used variadic mappings specifically.
97+
98+
Type: free text (optional)
99+
100+
101+
## Non-linear variadic generics
102+
103+
The following section refers to "non-linear" variadic generics.
104+
105+
"Linear" variadics generics, in this context, means generics that only map over types in a fixed order, and otherwise preserve a one-to-one correspondence between type parameters and derived types.
106+
107+
All the examples so far have been linear variadics.
108+
109+
"Non-linear" variadics generics mean things like filtering a tuple of types to only keep those that implement a trait, or reversing a tuple of types, or finding the first type in a tuple that implements a trait.
110+
111+
```rust
112+
fn get_children<...Ts>(parents: (...Ts)) -> (for <T of ...Ts where T: Parent> T::Child) {
113+
for parent in ...parents where parent: Parent {
114+
parent.child()
115+
}
116+
}
117+
```
118+
119+
### Are there cases where non-linear variadic generics would have made your project easier?
120+
121+
Type: select one
122+
123+
- Yes (same project as above)
124+
- Yes (another project)
125+
- No [`NEXT`](#how-high-a-priority-would-you-say-variadics-are-for-you)
126+
127+
### Can you give more details about the project?
128+
129+
Be as detailed as you like, more detail is better.
130+
131+
If it's the same project as before, you can include more details about how you would have used non-linear variadics specifically.
132+
133+
Type: free text (optional)
134+
135+
136+
## How high a priority would you say variadics are for you?
137+
138+
Type: select one
139+
140+
- It should be the highest priority feature.
141+
- Very important.
142+
- Moderately important.
143+
- Nice to have.
144+
- I don't care.
145+
- I don't want Rust to have variadics.

0 commit comments

Comments
 (0)