@@ -1072,6 +1072,15 @@ let p = Point {x: 10, y: 11};
10721072let 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
10771086An _ 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}
15351544struct_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.
15401552A _ structure expression_ consists of the [ path] ( #paths ) of a [ structure item] ( #structures ) ,
15411553followed by a brace-enclosed list of one or more comma-separated name-value pairs,
15421554providing the field values of a new instance of the structure.
15431555A field name can be any identifier, and is separated from its value expression by a colon.
15441556To 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+
15461563The 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;
15521570Point {x: 10f, y: 20f};
1571+ TuplePoint(10f, 20f);
15531572let 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
25972616The fields of a ` struct ` may be qualified by [ visibility modifiers] ( #visibility-modifiers ) ,
25982617to 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
0 commit comments