Skip to content

Commit e8abd2f

Browse files
kevinamarijnh
authored andcommitted
---
yaml --- r: 7317 b: refs/heads/master c: edf11eb h: refs/heads/master i: 7315: b1bc0b4 v: v3
1 parent 3f9b739 commit e8abd2f

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 96f1eda6d0ae0cf4f91d28304ded3996efda356a
2+
refs/heads/master: edf11ebf021dba897e5419cca53de3b652670799

trunk/doc/tutorial/data.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,24 @@ equivalent to a C enum:
103103
This will define `north`, `east`, `south`, and `west` as constants,
104104
all of which have type `direction`.
105105

106+
When the enum is is C like, that is none of the variants have
107+
parameters, it is possible to explicit set the discriminator values to
108+
an integer value:
109+
110+
enum color {
111+
red = 0xff0000;
112+
green = 0x00ff00;
113+
blue = 0x0000ff;
114+
}
115+
116+
If an explicit discriminator is not specified for a variant, the value
117+
defaults to the value of the previous variant plus one. If the first
118+
variant does not have a discriminator, it defaults to 0. For example,
119+
the value of `north` is 0, `east` is 1, etc.
120+
121+
When an enum is C-like the `as` cast operator can be used to get the
122+
discriminator's value.
123+
106124
<a name="single_variant_enum"></a>
107125

108126
There is a special case for enums with a single variant. These are

0 commit comments

Comments
 (0)