Skip to content

Commit 219647c

Browse files
authored
Merge pull request #204 from koic/replace_deprecated_range_syntax_with_new_range
Replace deprecated `...` range syntax with `..=`
2 parents e87acd0 + 90f17e6 commit 219647c

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

src/ch18-03-pattern-syntax.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -196,41 +196,41 @@ This code prints `one or two`.
196196
このコードは、`one or two`を出力します。
197197

198198
<!--
199-
### Matching Ranges of Values with `...`
199+
### Matching Ranges of Values with `..=`
200200
-->
201201

202-
### `...`で値の範囲に合致させる
202+
### `..=`で値の範囲に合致させる
203203

204204
<!--
205-
The `...` syntax allows us to match to an inclusive range of values. In the
205+
The `..=` syntax allows us to match to an inclusive range of values. In the
206206
following code, when a pattern matches any of the values within the range, that
207207
arm will execute:
208208
-->
209209

210-
`...`記法により、限度値を含む値の範囲にマッチさせることができます。以下のコードでは、
210+
`..=`記法により、限度値を含む値の範囲にマッチさせることができます。以下のコードでは、
211211
パターンが範囲内のどれかの値に合致すると、そのアームが実行されます:
212212

213213
```rust
214214
let x = 5;
215215

216216
match x {
217217
// 1から5まで
218-
1 ... 5 => println!("one through five"),
218+
1..=5 => println!("one through five"),
219219
// それ以外
220220
_ => println!("something else"),
221221
}
222222
```
223223

224224
<!--
225225
If `x` is 1, 2, 3, 4, or 5, the first arm will match. This syntax is more
226-
convenient than using the `|` operator to express the same idea; instead of `1
227-
... 5`, we would have to specify `1 | 2 | 3 | 4 | 5` if we used `|`. Specifying
226+
convenient than using the `|` operator to express the same idea; instead of `1..=5`,
227+
we would have to specify `1 | 2 | 3 | 4 | 5` if we used `|`. Specifying
228228
a range is much shorter, especially if we want to match, say, any number
229229
between 1 and 1,000!
230230
-->
231231

232232
`x`が1、2、3、4か5なら、最初のアームが合致します。この記法は、`|`演算子を使用して同じ考えを表現するより便利です;
233-
`1 ... 5`ではなく、`|`を使用したら、`1 | 2 | 3 | 4 | 5`と指定しなければならないでしょう。
233+
`1..=5`ではなく、`|`を使用したら、`1 | 2 | 3 | 4 | 5`と指定しなければならないでしょう。
234234
範囲を指定する方が遥かに短いのです。特に1から1000までの値と合致させたいとかなら!
235235

236236
<!--
@@ -253,9 +253,9 @@ let x = 'c';
253253

254254
match x {
255255
// ASCII文字前半
256-
'a' ... 'j' => println!("early ASCII letter"),
256+
'a'..='j' => println!("early ASCII letter"),
257257
// ASCII文字後半
258-
'k' ... 'z' => println!("late ASCII letter"),
258+
'k'..='z' => println!("late ASCII letter"),
259259
// それ以外
260260
_ => println!("something else"),
261261
}
@@ -1544,14 +1544,14 @@ were applied only to the final value in the list of values specified using the
15441544
The *at* operator (`@`) lets us create a variable that holds a value at the
15451545
same time we’re testing that value to see whether it matches a pattern. Listing
15461546
18-32 shows an example where we want to test that a `Message::Hello` `id` field
1547-
is within the range `3...7`. But we also want to bind the value to the variable
1547+
is within the range `3..=7`. But we also want to bind the value to the variable
15481548
`id_variable` so we can use it in the code associated with the arm. We could
15491549
name this variable `id`, the same as the field, but for this example we’ll use
15501550
a different name.
15511551
-->
15521552

15531553
*at*演算子(`@`)により、値を保持する変数を生成するのと同時にその値がパターンに一致するかを調べることができます。
1554-
リスト18-32は、`Message::Hello``id`フィールドが範囲`3...7`にあるかを確かめたいという例です。
1554+
リスト18-32は、`Message::Hello``id`フィールドが範囲`3..=7`にあるかを確かめたいという例です。
15551555
しかし、アームに紐づいたコードで使用できるように変数`id_variable`に値を束縛もしたいです。この変数をフィールドと同じ、
15561556
`id`と名付けることもできますが、この例では異なる名前にします。
15571557

@@ -1563,11 +1563,11 @@ enum Message {
15631563
let msg = Message::Hello { id: 5 };
15641564

15651565
match msg {
1566-
Message::Hello { id: id_variable @ 3...7 } => {
1566+
Message::Hello { id: id_variable @ 3..=7 } => {
15671567
// 範囲内のidが見つかりました: {}
15681568
println!("Found an id in range: {}", id_variable)
15691569
},
1570-
Message::Hello { id: 10...12 } => {
1570+
Message::Hello { id: 10..=12 } => {
15711571
// 別の範囲内のidが見つかりました
15721572
println!("Found an id in another range")
15731573
},
@@ -1587,11 +1587,11 @@ while also testing it</span>
15871587

15881588
<!--
15891589
This example will print `Found an id in range: 5`. By specifying `id_variable
1590-
@` before the range `3...7`, we’re capturing whatever value matched the range
1590+
@` before the range `3..=7`, we’re capturing whatever value matched the range
15911591
while also testing that the value matched the range pattern.
15921592
-->
15931593

1594-
この例は、`Found an id in range: 5`と出力します。範囲`3...7`の前に`id_variable @`と指定することで、
1594+
この例は、`Found an id in range: 5`と出力します。範囲`3..=7`の前に`id_variable @`と指定することで、
15951595
値が範囲パターンに一致することを確認しつつ、範囲にマッチしたどんな値も捕捉しています。
15961596

15971597
<!--

0 commit comments

Comments
 (0)