@@ -3801,7 +3801,7 @@ the value to a name with `@`:
38013801let x = 1i;
38023802
38033803match x {
3804- x @ 1 ... 5 => println!("got {}", x ),
3804+ e @ 1 ... 5 => println!("got a range element {}", e ),
38053805 _ => println!("anything"),
38063806}
38073807```
@@ -3834,7 +3834,7 @@ enum OptionalInt {
38343834let x = Value(5i);
38353835
38363836match 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!"),
38383838 Value(..) => println!("Got an int!"),
38393839 Missing => println!("No such luck."),
38403840}
@@ -3847,12 +3847,12 @@ with. First, `&`:
38473847let x = &5i;
38483848
38493849match x {
3850- &x => println!("Got a value: {}", x ),
3850+ &val => println!("Got a value: {}", val ),
38513851}
38523852```
38533853
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 `
38563856would be ` 5i ` .
38573857
38583858If 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:
38613861let x = 5i;
38623862
38633863match x {
3864- ref x => println!("Got a reference to {}", x ),
3864+ ref r => println!("Got a reference to {}", r ),
38653865}
38663866```
38673867
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 `
38693869keyword _ creates_ a reference, for use in the pattern. If you need a mutable
38703870reference, ` ref mut ` will work in the same way:
38713871
38723872``` {rust}
38733873let mut x = 5i;
38743874
38753875match x {
3876- ref mut x => println!("Got a mutable reference to {}", x ),
3876+ ref mut mr => println!("Got a mutable reference to {}", mr ),
38773877}
38783878```
38793879
0 commit comments