@@ -580,8 +580,8 @@ you use the matching to get at the contents of data types. Remember
580
580
that ` (float, float) ` is a tuple of two floats:
581
581
582
582
~~~~
583
- use float::consts::pi;
584
583
fn angle(vector: (float, float)) -> float {
584
+ let pi = float::consts::pi;
585
585
match vector {
586
586
(0f, y) if y < 0f => 1.5 * pi,
587
587
(0f, y) => 0.5 * pi,
@@ -601,23 +601,19 @@ an expression of type `bool` that determines, after the pattern is
601
601
found to match, whether the arm is taken or not. The variables bound
602
602
by the pattern are available in this guard expression.
603
603
604
- ## Let
605
-
606
- You've already seen simple ` let ` bindings. ` let ` is also a little fancier: it
607
- is possible to use destructuring patterns in it. For example, you can say this
608
- to extract the fields from a tuple:
604
+ You've already seen simple ` let ` bindings, but ` let ` is a little
605
+ fancier than you've been led to believe. It too supports destructuring
606
+ patterns. For example, you can say this to extract the fields from a
607
+ tuple, introducing two variables, ` a ` and ` b ` .
609
608
610
609
~~~~
611
610
# fn get_tuple_of_two_ints() -> (int, int) { (1, 1) }
612
611
let (a, b) = get_tuple_of_two_ints();
613
612
~~~~
614
613
615
- This will introduce two new variables, ` a ` and ` b ` , bound to the
616
- content of the tuple.
617
-
618
- You may only use * irrefutable* patterns—patterns that can never fail to
619
- match—in let bindings. Other types of patterns, such as literals, are
620
- not allowed.
614
+ Let bindings only work with _ irrefutable_ patterns, that is, patterns
615
+ that can never fail to match. This excludes ` let ` from matching
616
+ literals and most enum variants.
621
617
622
618
## Loops
623
619
0 commit comments