@@ -3801,7 +3801,7 @@ the value to a name with `@`:
3801
3801
let x = 1i;
3802
3802
3803
3803
match x {
3804
- x @ 1 ... 5 => println!("got {}", x ),
3804
+ e @ 1 ... 5 => println!("got a range element {}", e ),
3805
3805
_ => println!("anything"),
3806
3806
}
3807
3807
```
@@ -3834,7 +3834,7 @@ enum OptionalInt {
3834
3834
let x = Value(5i);
3835
3835
3836
3836
match x {
3837
- Value(x ) if x > 5 => println!("Got an int bigger than five!"),
3837
+ Value(i ) if i > 5 => println!("Got an int bigger than five!"),
3838
3838
Value(..) => println!("Got an int!"),
3839
3839
Missing => println!("No such luck."),
3840
3840
}
@@ -3847,12 +3847,12 @@ with. First, `&`:
3847
3847
let x = &5i;
3848
3848
3849
3849
match x {
3850
- &x => println!("Got a value: {}", x ),
3850
+ &val => println!("Got a value: {}", val ),
3851
3851
}
3852
3852
```
3853
3853
3854
- Here, the ` x ` inside the ` match ` has type ` int ` . In other words, the left hand
3855
- side of the pattern destructures the value. If we have ` &5i ` , then in ` &x ` , ` x `
3854
+ Here, the ` val ` inside the ` match ` has type ` int ` . In other words, the left hand
3855
+ side of the pattern destructures the value. If we have ` &5i ` , then in ` &val ` , ` val `
3856
3856
would be ` 5i ` .
3857
3857
3858
3858
If you want to get a reference, use the ` ref ` keyword:
@@ -3861,19 +3861,19 @@ If you want to get a reference, use the `ref` keyword:
3861
3861
let x = 5i;
3862
3862
3863
3863
match x {
3864
- ref x => println!("Got a reference to {}", x ),
3864
+ ref r => println!("Got a reference to {}", r ),
3865
3865
}
3866
3866
```
3867
3867
3868
- Here, the ` x ` inside the ` match ` has the type ` &int ` . In other words, the ` ref `
3868
+ Here, the ` r ` inside the ` match ` has the type ` &int ` . In other words, the ` ref `
3869
3869
keyword _ creates_ a reference, for use in the pattern. If you need a mutable
3870
3870
reference, ` ref mut ` will work in the same way:
3871
3871
3872
3872
``` {rust}
3873
3873
let mut x = 5i;
3874
3874
3875
3875
match x {
3876
- ref mut x => println!("Got a mutable reference to {}", x ),
3876
+ ref mut mr => println!("Got a mutable reference to {}", mr ),
3877
3877
}
3878
3878
```
3879
3879
0 commit comments