66
77<!-- We use them in [variable
88bindings][bindings], [match statements][match], and other places, too.-->
9- パターンは [ 変数束縛] [ bindings ] , [ マッチ文] [ match ] などで使われています。
9+ パターンは [ 変数束縛] [ bindings ] 、 [ マッチ文] [ match ] などで使われています。
1010
1111<!-- Let’s go on a whirlwind tour of all of the things patterns can do!-->
1212さあ、めくるめくパターンの旅を始めましょう!
@@ -33,7 +33,7 @@ match x {
3333これは ` one ` を表示します。
3434
3535<!-- There’s one pitfall with patterns: like anything that introduces a new binding,they introduce shadowing. For example: -->
36- パターンには一つ落とし穴があります。新しい束縛を導入すると、他の束縛を導入するものと同じように、シャドーイングします 。例えば:
36+ パターンには一つ落とし穴があります。新しい束縛を導入する他の構文と同様、パターンはシャドーイングをします 。例えば:
3737
3838``` rust
3939let x = 'x' ;
@@ -47,7 +47,7 @@ println!("x: {}", x)
4747```
4848
4949<!-- This prints:-->
50- これの結果は以下のようになります:
50+ これは以下のように出力します。
5151
5252``` text
5353x: c c: c
5757<!-- In other words, `x =>` matches the pattern and introduces a new binding named
5858`x` that’s in scope for the match arm. Because we already have a binding named
5959`x`, this new `x` shadows it. -->
60- 別の言い方をすると、 ` x => ` はパターンへのマッチだけでなく 、マッチの腕内で有効な ` x ` という名前の束縛を導入します。既に ` x ` は束縛されていたので、この新しい ` x ` はそれを覆い隠します 。
60+ 別の言い方をすると、 ` x => ` は値をパターンにマッチさせ 、マッチの腕内で有効な ` x ` という名前の束縛を導入します。既に ` x ` という束縛が存在していたので、新たに導入した ` x ` は、その古い ` x ` をシャドーイングします 。
6161
6262<!-- # Multiple patterns -->
6363# 複式パターン
6464
6565<!-- You can match multiple patterns with `|`: -->
66- ` | ` を使うと、複式パターンが導入できます :
66+ ` | ` を使うと、複数のパターンにマッチさせることができます :
6767
6868
6969``` rust
@@ -80,11 +80,11 @@ match x {
8080これは、 ` one or two ` を出力します。
8181
8282<!-- # Destructuring -->
83- # デストラクチャリング
83+ # 分配束縛
8484
8585<!-- If you have a compound data type, like a [`struct`][struct], you can destructure it
8686inside of a pattern: -->
87- 例えば [ ` struct ` ] [ struct ] のような複合データ型を作成したいとき、パターン内でデータを分解することができます 。
87+ [ ` struct ` ] [ struct ] のような複合データ型が存在するとき、パターン内でその値を分解することができます 。
8888
8989``` rust
9090struct Point {
@@ -118,7 +118,7 @@ match origin {
118118```
119119
120120<!-- If we only care about some of the values, we don’t have to give them all names: -->
121- 値の一部だけを扱いたい場合は、値の全てに名前を付ける必要はありません 。
121+ 値の一部にだけ興味がある場合は、値のすべてに名前を付ける必要はありません 。
122122
123123``` rust
124124struct Point {
@@ -137,7 +137,7 @@ match origin {
137137これは ` x is 0 ` を出力します。
138138
139139<!-- You can do this kind of match on any member, not just the first:-->
140- どのメンバに対してもこの種のマッチを行うことができます。たとえ最初ではなくても:
140+ 最初のメンバだけでなく、 どのメンバに対してもこの種のマッチを行うことができます。
141141
142142``` rust
143143struct Point {
@@ -157,7 +157,7 @@ match origin {
157157
158158<!-- This ‘destructuring’ behavior works on any compound data type, like
159159[tuples][tuples] or [enums][enums]. -->
160- この「デストラクチャリング (destructuring)」 と呼ばれる振る舞いは、 [ タプル] [ tuples ] や [ 列挙型] [ enums ] のような、複合データ型で使用できます 。
160+ この「分配束縛」 (destructuring) と呼ばれる振る舞いは、 [ タプル] [ tuples ] や [ 列挙型] [ enums ] のような、任意の複合データ型で使用できます 。
161161
162162[ tuples ] : primitive-types.html#tuples
163163[ enums ] : enums.html
@@ -169,7 +169,7 @@ match origin {
169169パターン内の型や値を無視するために ` _ ` を使うことができます。
170170
171171<!-- For example, here’s a `match` against a `Result<T, E>`: -->
172- 例として、 ` Result<T, E> ` に対して ` match ` を適用してみましょう :
172+ 例として、 ` Result<T, E> ` に対して ` match ` をしてみましょう :
173173
174174``` rust
175175# let some_value : Result <i32 , & 'static str > = Err (" There was an error" );
@@ -182,11 +182,11 @@ match some_value {
182182<!-- In the first arm, we bind the value inside the `Ok` variant to `value`. But
183183in the `Err` arm, we use `_` to disregard the specific error, and just print
184184a general error message. -->
185- 最初の部分では ` Ok ` ヴァリアント内の値を ` value ` に結びつけています 。しかし ` Err ` 部分では、特定のエラーを避けて、標準的なエラーメッセージを表示するために ` _ ` を使っています。
185+ 最初の部分では ` Ok ` ヴァリアント内の値に ` value ` を束縛しています 。しかし ` Err ` 部分では、ヴァリアント内のエラー情報を無視して一般的なエラーメッセージを表示するために ` _ ` を使っています。
186186
187187<!-- `_` is valid in any pattern that creates a binding. This can be useful to
188188ignore parts of a larger structure: -->
189- ` _ ` は束縛を伴うどんなパターンにおいても有効です。これは大きな構造の一部分を無視する際に有用です 。
189+ ` _ ` は束縛を導入するどのようなパターンにおいても有効です。これは大きな構造の一部を無視する際に有用です 。
190190
191191``` rust
192192fn coordinate () -> (i32 , i32 , i32 ) {
@@ -200,7 +200,7 @@ let (x, _, z) = coordinate();
200200
201201<!-- Here, we bind the first and last element of the tuple to `x` and `z`, but
202202ignore the middle element. -->
203- ここでは、タプルの最初と最後の要素を ` x ` と ` z ` に結びつけています 。
203+ ここでは、タプルの最初と最後の要素に ` x ` と ` z ` を束縛します 。
204204
205205<!-- Similarly, you can use `..` in a pattern to disregard multiple values. -->
206206同様に ` .. ` でパターン内の複数の値を無視することができます。
@@ -226,7 +226,7 @@ match x {
226226# ref と ref mut
227227
228228<!-- If you want to get a [reference][ref], use the `ref` keyword:-->
229- もし [ リファレンス ] [ ref ] を取得したいときは ` ref ` キーワードを使いましょう。
229+ [ 参照 ] [ ref ] を取得したいときは ` ref ` キーワードを使いましょう。
230230
231231``` rust
232232let x = 5 ;
@@ -244,7 +244,7 @@ match x {
244244<!-- Here, the `r` inside the `match` has the type `&i32`. In other words, the `ref`
245245keyword _creates_ a reference, for use in the pattern. If you need a mutable
246246reference, `ref mut` will work in the same way: -->
247- ここで ` match ` 内の ` r ` は ` &i32 ` 型を持っています。言い換えると ` ref ` キーワードがリファレンスを _ 作ります _ 。
247+ ここで ` match ` 内の ` r ` は ` &i32 ` 型を持っています。言い換えると、 ` ref ` キーワードはパターン内で使う参照を _ 作り出します _ 。ミュータブルな参照が必要な場合は、同様に ` ref mut ` を使います 。
248248
249249``` rust
250250let mut x = 5 ;
@@ -255,10 +255,10 @@ match x {
255255```
256256
257257<!-- # Ranges -->
258- # レンジ
258+ # 範囲
259259
260260<!-- You can match a range of values with `...`: -->
261- ` ... ` で値のレンジのマッチを行うことができます :
261+ ` ... ` で値の範囲をマッチさせることができます :
262262
263263``` rust
264264let x = 1 ;
@@ -273,7 +273,7 @@ match x {
273273これは ` one through five ` を出力します。
274274
275275<!-- Ranges are mostly used with integers and `char`s: -->
276- レンジは大体 、整数か ` char ` 型で使われます:
276+ 範囲は多くの場合 、整数か ` char ` 型で使われます:
277277
278278``` rust
279279let x = '💅' ;
@@ -292,7 +292,7 @@ match x {
292292# 束縛
293293
294294<!-- You can bind values to names with `@`: -->
295- ` @ ` で値を名前と結びつけることができます 。
295+ ` @ ` で値に名前を束縛することができます 。
296296
297297``` rust
298298let x = 1 ;
@@ -306,7 +306,7 @@ match x {
306306<!-- This prints `got a range element 1`. This is useful when you want to
307307do a complicated match of part of a data structure: -->
308308これは ` got a range element 1 ` を出力します。
309- データ構造の一部に対する複雑なマッチが欲しいときに有用です :
309+ データ構造の一部に対して複雑なマッチングをしたいときに有用です :
310310
311311``` rust
312312#[derive(Debug )]
@@ -323,11 +323,11 @@ match x {
323323```
324324
325325<!-- This prints `Some("Steve")`: we’ve bound the inner `name` to `a`.-->
326- これは ` Some("Steve") ` を出力します。内側の ` name ` を ` a ` に結びつけます 。
326+ これは ` Some("Steve") ` を出力します。内側の ` name ` の値への参照に ` a ` を束縛します 。
327327
328328<!-- If you use `@` with `|`, you need to make sure the name is bound in each part
329329of the pattern: -->
330- もし ` | ` で ` @ ` を使うときは、パターンのそれぞれの部分が名前と結びついているか確認する必要があります :
330+ ` @ ` を ` | ` と組み合わせて使う場合は、それぞれのパターンで同じ名前が束縛されるか確認する必要があります :
331331
332332``` rust
333333let x = 5 ;
@@ -363,7 +363,7 @@ match x {
363363これは ` Got an int! ` を出力します。
364364
365365<!-- If you’re using `if` with multiple patterns, the `if` applies to both sides:-->
366- 複式パターンで ` if ` を使うと、 ` if ` は両方に適用されます :
366+ 複式パターンで ` if ` を使うと、 ` if ` は ` | ` の両側に適用されます :
367367
368368``` rust
369369let x = 4 ;
@@ -377,7 +377,7 @@ match x {
377377
378378<!-- This prints `no`, because the `if` applies to the whole of `4 | 5`, and not to
379379just the `5`. In other words, the precedence of `if` behaves like this: -->
380- これは ` no ` を出力します。なぜなら ` if ` は ` 4 | 5 ` 全体に適用されるのであって、 ` 5 ` 単独に対してではないからです 。つまり ` if ` 節は以下のように振舞います:
380+ これは ` no ` を出力します。なぜなら ` if ` は ` 4 | 5 ` 全体に適用されるのであって、 ` 5 ` 単独に対して適用されるのではないからです 。つまり ` if ` 節は以下のように振舞います:
381381
382382``` text
383383(4 | 5) if y => ...
@@ -395,7 +395,7 @@ just the `5`. In other words, the precedence of `if` behaves like this: -->
395395
396396<!-- Whew! That’s a lot of different ways to match things, and they can all be
397397mixed and matched, depending on what you’re doing: -->
398- ふう、マッチには様々な方法があるのですね。やりたいこと次第で 、それらを混ぜてマッチさせることもできます:
398+ ふう、マッチには様々な方法があるのですね。やりたいことに応じて 、それらを混ぜてマッチさせることもできます:
399399
400400``` rust,ignore
401401match x {
0 commit comments