You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A struct expression that constructs a value of a struct type can terminate with the syntax `..` followed by an expression to denote a functional update.
130
+
131
+
r[expr.struct.update.base-same-type]
132
+
The expression following `..` (the base) must have the same struct type as the new struct type being formed.
133
+
134
+
r[expr.struct.update.fields]
135
+
The entire expression uses the given values for the fields that were specified and moves or copies the remaining fields from the base expression.
136
+
137
+
r[expr.struct.update.visibility-constraint]
138
+
As with all struct expressions, all of the fields of the struct must be [visible], even those not explicitly named.
139
+
140
+
```rust
141
+
# structPoint3d { x:i32, y:i32, z:i32 }
142
+
letmutbase=Point3d {x:1, y:2, z:3};
143
+
lety_ref=&mutbase.y;
144
+
Point3d {y:0, z:10, ..base}; // OK, only base.x is accessed
145
+
drop(y_ref);
146
+
```
147
+
148
+
r[expr.struct.default]
149
+
## Default field syntax
150
+
151
+
r[expr.struct.default.intro]
152
+
A struct expression that constructs a value of a struct type can terminate with the syntax `..` without a following expression to denote that unlisted fields should be set to their [default values].
153
+
154
+
r[expr.struct.default.fields]
155
+
All fields without defualt values must be listed in the expression.
156
+
The entire expression uses the given values for the fields that were specified and initializes the remaining fields with their respective default values.
157
+
158
+
r[expr.struct.default.visibility-constraint]
159
+
As with all struct expressions, all of the fields of the struct must be [visible], even those not explicitly named.
0 commit comments