Skip to content

Commit 87d026b

Browse files
committed
Improved pattern-match code and explanation.
This cleans up a warning about an unused variable and explains the code further.
1 parent acb1ec0 commit 87d026b

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/doc/tutorial.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ fn angle(vector: (f64, f64)) -> f64 {
509509
let pi = f64::consts::PI;
510510
match vector {
511511
(0.0, y) if y < 0.0 => 1.5 * pi,
512-
(0.0, y) => 0.5 * pi,
512+
(0.0, _) => 0.5 * pi,
513513
(x, y) => atan(y / x)
514514
}
515515
}
@@ -519,7 +519,9 @@ A variable name in a pattern matches any value, *and* binds that name
519519
to the value of the matched value inside of the arm's action. Thus, `(0.0,
520520
y)` matches any tuple whose first element is zero, and binds `y` to
521521
the second element. `(x, y)` matches any two-element tuple, and binds both
522-
elements to variables.
522+
elements to variables. `(0.0,_)` matches any tuple whose first element is zero
523+
and does not bind anything to the second element.
524+
523525
A subpattern can also be bound to a variable, using `variable @ pattern`. For
524526
example:
525527

0 commit comments

Comments
 (0)