File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -87,3 +87,33 @@ fn main() {
87
87
point.y = 6; // this causes an error
88
88
}
89
89
```
90
+
91
+ # Update syntax
92
+
93
+ A ` struct ` can include ` .. ` to indicate that you want to use a copy of some
94
+ other struct for some of the values. For example:
95
+
96
+ ``` rust
97
+ struct Point3d {
98
+ x : i32 ,
99
+ y : i32 ,
100
+ z : i32 ,
101
+ }
102
+
103
+ let mut point = Point3d { x : 0 , y : 0 , z : 0 };
104
+ point = Point3d { y : 1 , .. point };
105
+ ```
106
+
107
+ This gives ` point ` a new ` y ` , but keeps the old ` x ` and ` z ` values. It doesn’t
108
+ have to be the same ` struct ` either, you can use this syntax when making new
109
+ ones, and it will copy the values you don’t specify:
110
+
111
+ ``` rust
112
+ # struct Point3d {
113
+ # x : i32 ,
114
+ # y : i32 ,
115
+ # z : i32 ,
116
+ # }
117
+ let origin = Point3d { x : 0 , y : 0 , z : 0 };
118
+ let point = Point3d { z : 1 , x : 2 , .. origin };
119
+ ```
You can’t perform that action at this time.
0 commit comments