Skip to content

Commit fb6c428

Browse files
committed
---
yaml --- r: 39494 b: refs/heads/incoming c: e0072e3 h: refs/heads/master v: v3
1 parent e8a46b3 commit fb6c428

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
@@ -6,7 +6,7 @@ refs/heads/try: 3d5418789064fdb463e872a4e651af1c628a3650
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: a810c03263670238bccd64cabb12a23a46e3a278
9-
refs/heads/incoming: 46766974c73ff17a3b2cd4f2fb2cb06b7845ded4
9+
refs/heads/incoming: e0072e39a788ada2a636ab88a0b97534544c4125
1010
refs/heads/dist-snap: 22efa39382d41b084fde1719df7ae8ce5697d8c9
1111
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1212
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/incoming/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)