Skip to content

Commit 8875864

Browse files
committed
---
yaml --- r: 173941 b: refs/heads/auto c: a2e277e h: refs/heads/master i: 173939: a841482 v: v3
1 parent 20c91e5 commit 8875864

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
1010
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
1111
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1212
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
13-
refs/heads/auto: 868669f420df66c6acd866391a855200efa4a5d6
13+
refs/heads/auto: a2e277edf49cb05e79c0346de9a145e4ce6754cb
1414
refs/heads/servo: af82457af293e2a842ba6b7759b70288da276167
1515
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c
1616
refs/tags/0.1: b19db808c2793fe2976759b85a355c3ad8c8b336

branches/auto/src/doc/reference.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1413,6 +1413,27 @@ a = Animal::Cat { name: "Spotty".to_string(), weight: 2.7 };
14131413
In this example, `Cat` is a _struct-like enum variant_,
14141414
whereas `Dog` is simply called an enum variant.
14151415

1416+
Enums have a discriminant. You can assign them explicitly:
1417+
1418+
```
1419+
enum Foo {
1420+
Bar = 123,
1421+
}
1422+
```
1423+
1424+
If a discriminant isn't assigned, they start at zero, and add one for each
1425+
variant, in order.
1426+
1427+
You can cast an enum to get this value:
1428+
1429+
```
1430+
# enum Foo { Bar = 123 }
1431+
let x = Foo::Bar as u32; // x is now 123u32
1432+
```
1433+
1434+
This only works as long as none of the variants have data attached. If
1435+
it were `Bar(i32)`, this is disallowed.
1436+
14161437
### Constant items
14171438

14181439
```{.ebnf .gram}

0 commit comments

Comments
 (0)