Skip to content

Commit ab1f265

Browse files
committed
---
yaml --- r: 40931 b: refs/heads/dist-snap c: 8554d5e h: refs/heads/master i: 40929: 6423e16 40927: e59c756 v: v3
1 parent 6ace8d4 commit ab1f265

File tree

3 files changed

+38
-2
lines changed

3 files changed

+38
-2
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: a810c03263670238bccd64cabb12a23a46e3a278
99
refs/heads/incoming: e90142e536c150df0d9b4b2f11352152177509b5
10-
refs/heads/dist-snap: b99a2542f38a2d08b863d2e2ab73bfd64647e520
10+
refs/heads/dist-snap: 8554d5e7104be30d20ce8e8dc08239ce20b171c2
1111
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1212
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
1313
refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0

branches/dist-snap/doc/rust.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1072,6 +1072,15 @@ let p = Point {x: 10, y: 11};
10721072
let px: int = p.x;
10731073
~~~~
10741074

1075+
A _tuple structure_ is a nominal [tuple type](#tuple-types), also defined with the keyword `struct`.
1076+
For example:
1077+
1078+
~~~~
1079+
struct Point(int, int);
1080+
let p = Point(10, 11);
1081+
let px: int = match p { Point(x, _) => x };
1082+
~~~~
1083+
10751084
### Enumerations
10761085

10771086
An _enumeration_ is a simultaneous definition of a nominal [enumerated type](#enumerated-types) as well as a set of *constructors*,
@@ -1534,22 +1543,32 @@ values.
15341543
~~~~~~~~{.ebnf .gram}
15351544
struct_expr : expr_path '{' ident ':' expr
15361545
[ ',' ident ':' expr ] *
1537-
[ ".." expr ] '}'
1546+
[ ".." expr ] '}' |
1547+
expr_path '(' expr
1548+
[ ',' expr ] * ')'
15381549
~~~~~~~~
15391550

1551+
There are several forms of structure expressions.
15401552
A _structure expression_ consists of the [path](#paths) of a [structure item](#structures),
15411553
followed by a brace-enclosed list of one or more comma-separated name-value pairs,
15421554
providing the field values of a new instance of the structure.
15431555
A field name can be any identifier, and is separated from its value expression by a colon.
15441556
To indicate that a field is mutable, the `mut` keyword is written before its name.
15451557

1558+
A _tuple structure expression_ constists of the [path](#paths) of a [structure item](#structures),
1559+
followed by a parenthesized list of one or more comma-separated expressions
1560+
(in other words, the path of a structured item followed by a tuple expression).
1561+
The structure item must be a tuple structure item.
1562+
15461563
The following are examples of structure expressions:
15471564

15481565
~~~~
15491566
# struct Point { x: float, y: float }
1567+
# struct TuplePoint(float, float);
15501568
# mod game { pub struct User { name: &str, age: uint, mut score: uint } }
15511569
# use game;
15521570
Point {x: 10f, y: 20f};
1571+
TuplePoint(10f, 20f);
15531572
let u = game::User {name: "Joe", age: 35u, mut score: 100_000};
15541573
~~~~
15551574

@@ -2597,6 +2616,7 @@ the resulting `struct` value will always be laid out in memory in the order spec
25972616
The fields of a `struct` may be qualified by [visibility modifiers](#visibility-modifiers),
25982617
to restrict access to implementation-private data in a structure.
25992618

2619+
A `tuple struct` type is just like a structure type, except that the fields are anonymous.
26002620

26012621
### Enumerated types
26022622

branches/dist-snap/doc/tutorial.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -902,6 +902,22 @@ match mytup {
902902
}
903903
~~~~
904904

905+
## Tuple structs
906+
907+
Rust also has _nominal tuples_, which behave like both structs and tuples,
908+
except that nominal tuple types have names
909+
(so `Foo(1, 2)` has a different type from `Bar(1, 2)`),
910+
and nominal tuple types' _fields_ do not have names.
911+
912+
For example:
913+
~~~~
914+
struct MyTup(int, int, float);
915+
let mytup: MyTup = MyTup(10, 20, 30.0);
916+
match mytup {
917+
MyTup(a, b, c) => log(info, a + b + (c as int))
918+
}
919+
~~~~
920+
905921
# Functions and methods
906922

907923
We've already seen several function definitions. Like all other static

0 commit comments

Comments
 (0)