@@ -196,12 +196,27 @@ struct Point {
196
196
let origin = Point { x : 0 , y : 0 };
197
197
198
198
match origin {
199
- Point { x : x , y : y } => println! (" ({},{})" , x , y ),
199
+ Point { x , y } => println! (" ({},{})" , x , y ),
200
200
}
201
201
```
202
202
203
203
[ struct ] : structs.html
204
204
205
+ We can use ` : ` to give a value a different name.
206
+
207
+ ``` rust
208
+ struct Point {
209
+ x : i32 ,
210
+ y : i32 ,
211
+ }
212
+
213
+ let origin = Point { x : 0 , y : 0 };
214
+
215
+ match origin {
216
+ Point { x : x1 , y : y1 } => println! (" ({},{})" , x1 , y1 ),
217
+ }
218
+ ```
219
+
205
220
If we only care about some of the values, we don’t have to give them all names:
206
221
207
222
``` rust
@@ -213,7 +228,7 @@ struct Point {
213
228
let origin = Point { x : 0 , y : 0 };
214
229
215
230
match origin {
216
- Point { x : x , .. } => println! (" x is {}" , x ),
231
+ Point { x , .. } => println! (" x is {}" , x ),
217
232
}
218
233
```
219
234
@@ -230,7 +245,7 @@ struct Point {
230
245
let origin = Point { x : 0 , y : 0 };
231
246
232
247
match origin {
233
- Point { y : y , .. } => println! (" y is {}" , y ),
248
+ Point { y , .. } => println! (" y is {}" , y ),
234
249
}
235
250
```
236
251
0 commit comments