about summary refs log tree commit diff
diff options
context:
space:
mode:
authorKevin Atkinson <kevina@cs.utah.edu>2012-01-15 17:10:59 -0700
committerMarijn Haverbeke <marijnh@gmail.com>2012-01-16 11:19:32 +0100
commitedf11ebf021dba897e5419cca53de3b652670799 (patch)
tree09bd3a8e6dbc9a6b2c282f345fab720dd8d02b43
parent96f1eda6d0ae0cf4f91d28304ded3996efda356a (diff)
downloadrust-edf11ebf021dba897e5419cca53de3b652670799.tar.gz
rust-edf11ebf021dba897e5419cca53de3b652670799.zip
In the tutorial, document that C-like enums can have the discriminator
values set and that it is possible to cast them to scalar values.
-rw-r--r--doc/tutorial/data.md18
1 files changed, 18 insertions, 0 deletions
diff --git a/doc/tutorial/data.md b/doc/tutorial/data.md
index 678714d388b..7796da21382 100644
--- a/doc/tutorial/data.md
+++ b/doc/tutorial/data.md
@@ -103,6 +103,24 @@ equivalent to a C enum:
 This will define `north`, `east`, `south`, and `west` as constants,
 all of which have type `direction`.
 
+When the enum is is C like, that is none of the variants have
+parameters, it is possible to explicit set the discriminator values to
+an integer value:
+
+    enum color {
+      red = 0xff0000;
+      green = 0x00ff00;
+      blue = 0x0000ff;
+    }
+
+If an explicit discriminator is not specified for a variant, the value
+defaults to the value of the previous variant plus one.  If the first
+variant does not have a discriminator, it defaults to 0.  For example,
+the value of `north` is 0, `east` is 1, etc.
+
+When an enum is C-like the `as` cast operator can be used to get the
+discriminator's value.
+
 <a name="single_variant_enum"></a>
 
 There is a special case for enums with a single variant. These are