@@ -221,12 +221,27 @@ struct Point {
221221let origin = Point { x : 0 , y : 0 };
222222
223223match origin {
224- Point { x : x , y : y } => println! (" ({},{})" , x , y ),
224+ Point { x , y } => println! (" ({},{})" , x , y ),
225225}
226226```
227227
228228[ struct ] : structs.html
229229
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+
230245If we only care about some of the values, we don’t have to give them all names:
231246
232247``` rust
@@ -238,7 +253,7 @@ struct Point {
238253let origin = Point { x : 0 , y : 0 };
239254
240255match origin {
241- Point { x : x , .. } => println! (" x is {}" , x ),
256+ Point { x , .. } => println! (" x is {}" , x ),
242257}
243258```
244259
@@ -255,7 +270,7 @@ struct Point {
255270let origin = Point { x : 0 , y : 0 };
256271
257272match origin {
258- Point { y : y , .. } => println! (" y is {}" , y ),
273+ Point { y , .. } => println! (" y is {}" , y ),
259274}
260275```
261276
0 commit comments