@@ -34767,15 +34767,15 @@ <h3 id="複数のパターン"><a class="header" href="#複数のパターン">
34767
34767
-->
34768
34768
<p>このコードは、<code>one or two</code>を出力します。</p>
34769
34769
<!--
34770
- ### Matching Ranges of Values with `... `
34770
+ ### Matching Ranges of Values with `..= `
34771
34771
-->
34772
- <h3 id="で値の範囲に合致させる"><a class="header" href="#で値の範囲に合致させる"><code>... </code>で値の範囲に合致させる</a></h3>
34772
+ <h3 id="で値の範囲に合致させる"><a class="header" href="#で値の範囲に合致させる"><code>..= </code>で値の範囲に合致させる</a></h3>
34773
34773
<!--
34774
- The `... ` syntax allows us to match to an inclusive range of values. In the
34774
+ The `..= ` syntax allows us to match to an inclusive range of values. In the
34775
34775
following code, when a pattern matches any of the values within the range, that
34776
34776
arm will execute:
34777
34777
-->
34778
- <p><code>... </code>記法により、限度値を含む値の範囲にマッチさせることができます。以下のコードでは、
34778
+ <p><code>..= </code>記法により、限度値を含む値の範囲にマッチさせることができます。以下のコードでは、
34779
34779
パターンが範囲内のどれかの値に合致すると、そのアームが実行されます:</p>
34780
34780
<pre><pre class="playground"><code class="language-rust">
34781
34781
<span class="boring">#![allow(unused)]
@@ -34784,21 +34784,21 @@ <h3 id="で値の範囲に合致させる"><a class="header" href="#で値の範
34784
34784
34785
34785
match x {
34786
34786
// 1から5まで
34787
- 1 ... 5 => println!("one through five"),
34787
+ 1..= 5 => println!("one through five"),
34788
34788
// それ以外
34789
34789
_ => println!("something else"),
34790
34790
}
34791
34791
<span class="boring">}
34792
34792
</span></code></pre></pre>
34793
34793
<!--
34794
34794
If `x` is 1, 2, 3, 4, or 5, the first arm will match. This syntax is more
34795
- convenient than using the `|` operator to express the same idea; instead of `1
34796
- ... 5`, we would have to specify `1 | 2 | 3 | 4 | 5` if we used `|`. Specifying
34795
+ convenient than using the `|` operator to express the same idea; instead of `1..=5`,
34796
+ we would have to specify `1 | 2 | 3 | 4 | 5` if we used `|`. Specifying
34797
34797
a range is much shorter, especially if we want to match, say, any number
34798
34798
between 1 and 1,000!
34799
34799
-->
34800
34800
<p><code>x</code>が1、2、3、4か5なら、最初のアームが合致します。この記法は、<code>|</code>演算子を使用して同じ考えを表現するより便利です;
34801
- <code>1 ... 5</code>ではなく、<code>|</code>を使用したら、<code>1 | 2 | 3 | 4 | 5</code>と指定しなければならないでしょう。
34801
+ <code>1..= 5</code>ではなく、<code>|</code>を使用したら、<code>1 | 2 | 3 | 4 | 5</code>と指定しなければならないでしょう。
34802
34802
範囲を指定する方が遥かに短いのです。特に1から1000までの値と合致させたいとかなら!</p>
34803
34803
<!--
34804
34804
Ranges are only allowed with numeric values or `char` values, because the
@@ -34818,9 +34818,9 @@ <h3 id="で値の範囲に合致させる"><a class="header" href="#で値の範
34818
34818
34819
34819
match x {
34820
34820
// ASCII文字前半
34821
- 'a' ... 'j' => println!("early ASCII letter"),
34821
+ 'a'..= 'j' => println!("early ASCII letter"),
34822
34822
// ASCII文字後半
34823
- 'k' ... 'z' => println!("late ASCII letter"),
34823
+ 'k'..= 'z' => println!("late ASCII letter"),
34824
34824
// それ以外
34825
34825
_ => println!("something else"),
34826
34826
}
@@ -35885,13 +35885,13 @@ <h3 id="束縛"><a class="header" href="#束縛"><code>@</code>束縛</a></h3>
35885
35885
The *at* operator (`@`) lets us create a variable that holds a value at the
35886
35886
same time we’re testing that value to see whether it matches a pattern. Listing
35887
35887
18-32 shows an example where we want to test that a `Message::Hello` `id` field
35888
- is within the range `3... 7`. But we also want to bind the value to the variable
35888
+ is within the range `3..= 7`. But we also want to bind the value to the variable
35889
35889
`id_variable` so we can use it in the code associated with the arm. We could
35890
35890
name this variable `id`, the same as the field, but for this example we’ll use
35891
35891
a different name.
35892
35892
-->
35893
35893
<p><em>at</em>演算子(<code>@</code>)により、値を保持する変数を生成するのと同時にその値がパターンに一致するかを調べることができます。
35894
- リスト18-32は、<code>Message::Hello</code>の<code>id</code>フィールドが範囲<code>3... 7</code>にあるかを確かめたいという例です。
35894
+ リスト18-32は、<code>Message::Hello</code>の<code>id</code>フィールドが範囲<code>3..= 7</code>にあるかを確かめたいという例です。
35895
35895
しかし、アームに紐づいたコードで使用できるように変数<code>id_variable</code>に値を束縛もしたいです。この変数をフィールドと同じ、
35896
35896
<code>id</code>と名付けることもできますが、この例では異なる名前にします。</p>
35897
35897
<pre><pre class="playground"><code class="language-rust">
@@ -35904,11 +35904,11 @@ <h3 id="束縛"><a class="header" href="#束縛"><code>@</code>束縛</a></h3>
35904
35904
let msg = Message::Hello { id: 5 };
35905
35905
35906
35906
match msg {
35907
- Message::Hello { id: id_variable @ 3... 7 } => {
35907
+ Message::Hello { id: id_variable @ 3..= 7 } => {
35908
35908
// 範囲内のidが見つかりました: {}
35909
35909
println!("Found an id in range: {}", id_variable)
35910
35910
},
35911
- Message::Hello { id: 10... 12 } => {
35911
+ Message::Hello { id: 10..= 12 } => {
35912
35912
// 別の範囲内のidが見つかりました
35913
35913
println!("Found an id in another range")
35914
35914
},
@@ -35926,10 +35926,10 @@ <h3 id="束縛"><a class="header" href="#束縛"><code>@</code>束縛</a></h3>
35926
35926
<p><span class="caption"><code>@</code>を使用してテストしつつ、パターンの値に束縛する</span></p>
35927
35927
<!--
35928
35928
This example will print `Found an id in range: 5`. By specifying `id_variable
35929
- @` before the range `3... 7`, we’re capturing whatever value matched the range
35929
+ @` before the range `3..= 7`, we’re capturing whatever value matched the range
35930
35930
while also testing that the value matched the range pattern.
35931
35931
-->
35932
- <p>この例は、<code>Found an id in range: 5</code>と出力します。範囲<code>3... 7</code>の前に<code>id_variable @</code>と指定することで、
35932
+ <p>この例は、<code>Found an id in range: 5</code>と出力します。範囲<code>3..= 7</code>の前に<code>id_variable @</code>と指定することで、
35933
35933
値が範囲パターンに一致することを確認しつつ、範囲にマッチしたどんな値も捕捉しています。</p>
35934
35934
<!--
35935
35935
In the second arm, where we only have a range specified in the pattern, the code
0 commit comments