Skip to content

Commit aec2f34

Browse files
committed
---
yaml --- r: 36829 b: refs/heads/try2 c: e0072e3 h: refs/heads/master i: 36827: ed4813c v: v3
1 parent 03366f0 commit aec2f34

File tree

2 files changed

+38
-3
lines changed

2 files changed

+38
-3
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: eb8fd119c65c67f3b1b8268cc7341c22d39b7b61
55
refs/heads/try: d324a424d8f84b1eb049b12cf34182bda91b0024
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: 46766974c73ff17a3b2cd4f2fb2cb06b7845ded4
8+
refs/heads/try2: e0072e39a788ada2a636ab88a0b97534544c4125
99
refs/heads/incoming: d9317a174e434d4c99fc1a37fd7dc0d2f5328d37
1010
refs/heads/dist-snap: 22efa39382d41b084fde1719df7ae8ce5697d8c9
1111
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596

branches/try2/doc/rust.md

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1503,6 +1503,39 @@ values.
15031503
("a", 4u, true);
15041504
~~~~~~~~
15051505

1506+
### Structure expressions
1507+
1508+
~~~~~~~~{.ebnf .gram}
1509+
struct_expr : expr_path '{' ident ':' expr
1510+
[ ',' ident ':' expr ] *
1511+
[ ".." expr ] '}'
1512+
~~~~~~~~
1513+
1514+
A _structure expression_ consists of the [path](#paths) of a [structure item](#structures),
1515+
followed by a brace-enclosed list of one or more comma-separated name-value pairs,
1516+
providing the field values of a new instance of the structure.
1517+
A field name can be any identifier, and is separated from its value expression by a colon.
1518+
To indicate that a field is mutable, the `mut` keyword is written before its name.
1519+
1520+
The following are examples of structure expressions:
1521+
1522+
~~~~
1523+
Point {x: 10f, y: 20f};
1524+
game::User {name: "Joe", age: 35u, mut score: 100_000};
1525+
~~~~
1526+
1527+
A structure expression forms a new value of the named structure type.
1528+
1529+
A structure expression can terminate with the syntax `..` followed by an expression to denote a functional update.
1530+
The expression following `..` (the base) must be of the same structure type as the new structure type being formed.
1531+
A new structure will be created, of the same type as the base expression, with the given values for the fields that were explicitly specified,
1532+
and the values in the base record for all other fields.
1533+
1534+
~~~~
1535+
let base = Point3d {x: 1, y: 2, z: 3};
1536+
Point3d {y: 0, z: 10, .. base};
1537+
~~~~
1538+
15061539
### Record expressions
15071540

15081541
~~~~~~~~{.ebnf .gram}
@@ -1511,9 +1544,11 @@ rec_expr : '{' ident ':' expr
15111544
[ ".." expr ] '}'
15121545
~~~~~~~~
15131546

1547+
> **Note:** In future versions of Rust, record expressions and [record types](#record-types) will be removed.
1548+
15141549
A [_record_](#record-types) _expression_ is one or more comma-separated
1515-
name-value pairs enclosed by braces. A fieldname can be any identifier
1516-
(including keywords), and is separated from its value expression by a
1550+
name-value pairs enclosed by braces. A fieldname can be any identifier,
1551+
and is separated from its value expression by a
15171552
colon. To indicate that a field is mutable, the `mut` keyword is
15181553
written before its name.
15191554

0 commit comments

Comments
 (0)