Skip to content

Commit 665a475

Browse files
committed
---
yaml --- r: 34301 b: refs/heads/snap-stage3 c: 3cc0fbc h: refs/heads/master i: 34299: 29907b9 v: v3
1 parent 3dfa76e commit 665a475

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: cd6f24f9d14ac90d167386a56e7a6ac1f0318195
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: 499a58708f7576f2c9d5b6eb266a7fe855eff419
4+
refs/heads/snap-stage3: 3cc0fbca5d0a37f9b770db27e3ea39a00616ca4f
55
refs/heads/try: d324a424d8f84b1eb049b12cf34182bda91b0024
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b

branches/snap-stage3/doc/rust.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,6 +1107,19 @@ let mut a: Animal = Dog;
11071107
a = Cat;
11081108
~~~~
11091109

1110+
Enumeration constructors can have either named or unnamed fields:
1111+
~~~~
1112+
enum Animal {
1113+
Dog (~str, float),
1114+
Cat { name: ~str, weight: float }
1115+
}
1116+
1117+
let mut a: Animal = Dog(~"Cocoa", 37.2);
1118+
a = Cat{ name: ~"Spotty", weight: 2.7 };
1119+
~~~~
1120+
1121+
In this example, `Cat` is a _struct-like enum variant_,
1122+
whereas `Dog` is simply called an enum variant.
11101123
### Constants
11111124

11121125
~~~~~~~~ {.ebnf .gram}

branches/snap-stage3/doc/tutorial.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -733,6 +733,24 @@ fn point_from_direction(dir: Direction) -> Point {
733733
}
734734
~~~~
735735

736+
A special kind of enum variant, called _struct-like enums_,
737+
can have its fields extracted with dot notation and not just destructuring.
738+
For example:
739+
740+
~~~~
741+
# struct Point {x: float, y: float}
742+
# fn square(x: float) -> float { x * x }
743+
enum Shape {
744+
Circle { center: Point, radius: float },
745+
Rectangle { left: Point, right: Point }
746+
}
747+
fn area(sh: Shape) -> float {
748+
match sh {
749+
Circle(c) => float::consts::pi * square(c.radius),
750+
Rectangle(r) => r.right.x - r.left.x * r.right.y - r.right.y
751+
}
752+
}
753+
~~~~
736754
## Tuples
737755

738756
Tuples in Rust behave exactly like structs, except that their fields

0 commit comments

Comments
 (0)