Skip to content

Commit 18565c6

Browse files
committed
book: update example patterns to be more clear
When using Point { x: 0, y: 0 } and showing pattern matching decomposing x and y individually its hard to understand. By using a different value for x and a different value for y it is more clear.
1 parent 42903d9 commit 18565c6

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/doc/book/patterns.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -109,14 +109,14 @@ struct Point {
109109
y: i32,
110110
}
111111

112-
let origin = Point { x: 0, y: 0 };
112+
let point = Point { x: 2, y: 3 };
113113

114-
match origin {
114+
match point {
115115
Point { x, .. } => println!("x is {}", x),
116116
}
117117
```
118118

119-
This prints `x is 0`.
119+
This prints `x is 2`.
120120

121121
You can do this kind of match on any member, not only the first:
122122

@@ -126,14 +126,14 @@ struct Point {
126126
y: i32,
127127
}
128128

129-
let origin = Point { x: 0, y: 0 };
129+
let point = Point { x: 2, y: 3 };
130130

131-
match origin {
131+
match point {
132132
Point { y, .. } => println!("y is {}", y),
133133
}
134134
```
135135

136-
This prints `y is 0`.
136+
This prints `y is 3`.
137137

138138
This ‘destructuring’ behavior works on any compound data type, like
139139
[tuples][tuples] or [enums][enums].

0 commit comments

Comments
 (0)