Skip to content

Commit c199e13

Browse files
authored
Merge pull request #1977 from kevinmehall/patch-1
Replace deprecated `...` range syntax with `..=`
2 parents 4badf9a + 158c5eb commit c199e13

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

src/ch18-03-pattern-syntax.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -105,24 +105,24 @@ match x {
105105

106106
This code prints `one or two`.
107107

108-
### Matching Ranges of Values with `...`
108+
### Matching Ranges of Values with `..=`
109109

110-
The `...` syntax allows us to match to an inclusive range of values. In the
110+
The `..=` syntax allows us to match to an inclusive range of values. In the
111111
following code, when a pattern matches any of the values within the range, that
112112
arm will execute:
113113

114114
```rust
115115
let x = 5;
116116

117117
match x {
118-
1...5 => println!("one through five"),
118+
1..=5 => println!("one through five"),
119119
_ => println!("something else"),
120120
}
121121
```
122122

123123
If `x` is 1, 2, 3, 4, or 5, the first arm will match. This syntax is more
124124
convenient than using the `|` operator to express the same idea; instead of
125-
`1...5`, we would have to specify `1 | 2 | 3 | 4 | 5` if we used `|`.
125+
`1..=5`, we would have to specify `1 | 2 | 3 | 4 | 5` if we used `|`.
126126
Specifying a range is much shorter, especially if we want to match, say, any
127127
number between 1 and 1,000!
128128

@@ -136,8 +136,8 @@ Here is an example using ranges of `char` values:
136136
let x = 'c';
137137

138138
match x {
139-
'a'...'j' => println!("early ASCII letter"),
140-
'k'...'z' => println!("late ASCII letter"),
139+
'a'..='j' => println!("early ASCII letter"),
140+
'k'..='z' => println!("late ASCII letter"),
141141
_ => println!("something else"),
142142
}
143143
```
@@ -783,7 +783,7 @@ were applied only to the final value in the list of values specified using the
783783
The *at* operator (`@`) lets us create a variable that holds a value at the
784784
same time we’re testing that value to see whether it matches a pattern. Listing
785785
18-29 shows an example where we want to test that a `Message::Hello` `id` field
786-
is within the range `3...7`. But we also want to bind the value to the variable
786+
is within the range `3..=7`. But we also want to bind the value to the variable
787787
`id_variable` so we can use it in the code associated with the arm. We could
788788
name this variable `id`, the same as the field, but for this example we’ll use
789789
a different name.
@@ -796,10 +796,10 @@ enum Message {
796796
let msg = Message::Hello { id: 5 };
797797

798798
match msg {
799-
Message::Hello { id: id_variable @ 3...7 } => {
799+
Message::Hello { id: id_variable @ 3..=7 } => {
800800
println!("Found an id in range: {}", id_variable)
801801
},
802-
Message::Hello { id: 10...12 } => {
802+
Message::Hello { id: 10..=12 } => {
803803
println!("Found an id in another range")
804804
},
805805
Message::Hello { id } => {
@@ -812,7 +812,7 @@ match msg {
812812
while also testing it</span>
813813

814814
This example will print `Found an id in range: 5`. By specifying `id_variable
815-
@` before the range `3...7`, we’re capturing whatever value matched the range
815+
@` before the range `3..=7`, we’re capturing whatever value matched the range
816816
while also testing that the value matched the range pattern.
817817

818818
In the second arm, where we only have a range specified in the pattern, the code

0 commit comments

Comments
 (0)