File tree Expand file tree Collapse file tree 1 file changed +30
-3
lines changed Expand file tree Collapse file tree 1 file changed +30
-3
lines changed Original file line number Diff line number Diff line change @@ -231,9 +231,12 @@ This introduces one more knob to the representation of enumerations.
231
231
232
232
Reusing the current syntax and semantics for explicit discriminants of
233
233
field-less enumerations means that the changes to the grammar and semantics of
234
- the language are minimal. The alternative is to put the specified discriminants
235
- in variant attributes, but this would be at odds with the syntax for field-less
236
- enumerations.
234
+ the language are minimal. There are a few possible alternatives nonetheless.
235
+
236
+ ## Discriminant values in attributes
237
+
238
+ We could specify the discriminant values in variant attributes, but this would
239
+ be at odds with the syntax for field-less enumerations.
237
240
238
241
``` rust
239
242
enum ParisianSandwichIngredient {
@@ -246,6 +249,30 @@ enum ParisianSandwichIngredient {
246
249
}
247
250
```
248
251
252
+ ## Use discriminants of a separate field-less enumeration
253
+
254
+ We could tell rustc to tie the discriminants of the enumeration to the
255
+ variants of a separate field-less enumeration.
256
+
257
+ ``` rust
258
+ #[discriminant(IngredientKind )]
259
+ enum ParisianSandwichIngredient {
260
+ Bread (BreadKind ),
261
+ Ham (HamKind ),
262
+ Butter (ButterKind ),
263
+ }
264
+
265
+ enum IngredientKind {
266
+ Bread ,
267
+ Ham ,
268
+ Butter ,
269
+ }
270
+ ```
271
+
272
+ This isn't applicable if such a separate field-less enumeration doesn't exist,
273
+ and this can easily be done as a procedural macro using the feature described
274
+ in this RFC. It also looks way more like spooky action at a distance.
275
+
249
276
# Prior art
250
277
[ prior-art ] : #prior-art
251
278
You can’t perform that action at this time.
0 commit comments