Skip to content

Commit 871487b

Browse files
committed
Add variadic generics survey
1 parent c2a521a commit 871487b

File tree

1 file changed

+144
-0
lines changed

1 file changed

+144
-0
lines changed
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
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 one
32+
33+
- Yes, through Pre-RFCs and discussions on `internals.rust-lang.org`.
34+
- Yes, through discussions on Reddit.
35+
- Yes, through blog posts on `poignardazur.github.io`.
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 on 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+
A Github link would be ideal. Otherwise, a description of the projects and what you would have needed variadics for.
54+
55+
Type: free text
56+
57+
58+
## Variadic type mappings
59+
60+
The following section refers to "mappings" of variadic generics.
61+
62+
In this context, variadic mappings refer to code take N-tuples of types as generic parameters, and declare N-tuples of types, where each type in the tuple is transformed in the same way.
63+
64+
For example:
65+
66+
```rust
67+
impl<...Ts> UnwrapAll for (Option<...Ts>) {
68+
type Unwrapped = (...Ts);
69+
fn unwrap_all(self) -> Self::Unwrapped {
70+
for option in ...self {
71+
option.unwrap()
72+
}
73+
}
74+
}
75+
76+
let my_gift_boxes = (Some(1), Some(true), Some("hello"));
77+
let opened_gifts = my_gift_boxes.unwrap_all();
78+
assert_eq!(opened_gifts, (1, true, "hello"));
79+
```
80+
81+
In that example, the trait `UnwrapAll` maps `u32, bool, &str` to `Option<u32>, Option<bool>, Option<&str>`.
82+
83+
### Are there cases where variadic mappings would have made your project easier?
84+
85+
Type: select one
86+
87+
- Yes (same project as above)
88+
- Yes (another project)
89+
- No [`NEXT`](#non-linear-variadic-generics)
90+
91+
### Can you give more details about the project?
92+
93+
Please include Github link and/or description.
94+
95+
If it's the same project as before, you can include more details about how you would have used variadic mappings specifically.
96+
97+
Type: free text (optional)
98+
99+
100+
## Non-linear variadic generics
101+
102+
The following section refers to "non-linear" variadic generics.
103+
104+
"Linear" variadics generics, in this context, means generics which only map over types in a fixed order, and otherwise preserve a one-to-one correspondance between type parameters and derived types.
105+
106+
All the examples so far have been linear variadics.
107+
108+
"Non-linear" variadics generics mean things like filtering a tuple of types to only keeps those that implement a trait, or reversing a list of types, or finding the first type in a list that implements a trait.
109+
110+
```rust
111+
fn get_children<...Ts>(parents: (...Ts)) -> (for <T of ...Ts where T: Parent> T::Child) {
112+
for parent in ...parents where parent: Parent {
113+
parent.child()
114+
}
115+
}
116+
```
117+
118+
### Are there cases where non-linear variadic generics would have made your project easier?
119+
120+
Type: select one
121+
122+
- Yes (same project as above)
123+
- Yes (another project)
124+
- No [`NEXT`](#how-high-a-priority-would-you-say-variadics-are-for-you)
125+
126+
### Can you give more details about the project?
127+
128+
Please include Github link and/or description.
129+
130+
If it's the same project as before, you can include more details about how you would have used non-linear variadics specifically.
131+
132+
Type: free text (optional)
133+
134+
135+
## How high a priority would you say variadics are for you?
136+
137+
Type: select one
138+
139+
- It should be the highest priority feature.
140+
- Very important.
141+
- Moderately important.
142+
- Nice to have.
143+
- I don't care.
144+
- I don't want Rust to have variadics.

0 commit comments

Comments
 (0)