@@ -221,12 +221,27 @@ struct Point {
221
221
let origin = Point { x : 0 , y : 0 };
222
222
223
223
match origin {
224
- Point { x : x , y : y } => println! (" ({},{})" , x , y ),
224
+ Point { x , y } => println! (" ({},{})" , x , y ),
225
225
}
226
226
```
227
227
228
228
[ struct ] : structs.html
229
229
230
+ We can use ` : ` to give a value a different name.
231
+
232
+ ``` rust
233
+ struct Point {
234
+ x : i32 ,
235
+ y : i32 ,
236
+ }
237
+
238
+ let origin = Point { x : 0 , y : 0 };
239
+
240
+ match origin {
241
+ Point { x : x1 , y : y1 } => println! (" ({},{})" , x1 , y1 ),
242
+ }
243
+ ```
244
+
230
245
If we only care about some of the values, we don’t have to give them all names:
231
246
232
247
``` rust
@@ -238,7 +253,7 @@ struct Point {
238
253
let origin = Point { x : 0 , y : 0 };
239
254
240
255
match origin {
241
- Point { x : x , .. } => println! (" x is {}" , x ),
256
+ Point { x , .. } => println! (" x is {}" , x ),
242
257
}
243
258
```
244
259
@@ -255,7 +270,7 @@ struct Point {
255
270
let origin = Point { x : 0 , y : 0 };
256
271
257
272
match origin {
258
- Point { y : y , .. } => println! (" y is {}" , y ),
273
+ Point { y , .. } => println! (" y is {}" , y ),
259
274
}
260
275
```
261
276
0 commit comments