@@ -196,12 +196,27 @@ struct Point {
196196let origin = Point { x : 0 , y : 0 };
197197
198198match origin {
199- Point { x : x , y : y } => println! (" ({},{})" , x , y ),
199+ Point { x , y } => println! (" ({},{})" , x , y ),
200200}
201201```
202202
203203[ struct ] : structs.html
204204
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+
205220If we only care about some of the values, we don’t have to give them all names:
206221
207222``` rust
@@ -213,7 +228,7 @@ struct Point {
213228let origin = Point { x : 0 , y : 0 };
214229
215230match origin {
216- Point { x : x , .. } => println! (" x is {}" , x ),
231+ Point { x , .. } => println! (" x is {}" , x ),
217232}
218233```
219234
@@ -230,7 +245,7 @@ struct Point {
230245let origin = Point { x : 0 , y : 0 };
231246
232247match origin {
233- Point { y : y , .. } => println! (" y is {}" , y ),
248+ Point { y , .. } => println! (" y is {}" , y ),
234249}
235250```
236251
0 commit comments