6
6
7
7
<!-- We use them in [variable
8
8
bindings][bindings], [match statements][match], and other places, too.-->
9
- パターンは [ 変数束縛] [ bindings ] , [ マッチ文] [ match ] などで使われています。
9
+ パターンは [ 変数束縛] [ bindings ] 、 [ マッチ文] [ match ] などで使われています。
10
10
11
11
<!-- Let’s go on a whirlwind tour of all of the things patterns can do!-->
12
12
さあ、めくるめくパターンの旅を始めましょう!
@@ -33,7 +33,7 @@ match x {
33
33
これは ` one ` を表示します。
34
34
35
35
<!-- There’s one pitfall with patterns: like anything that introduces a new binding,they introduce shadowing. For example: -->
36
- パターンには一つ落とし穴があります。新しい束縛を導入すると、他の束縛を導入するものと同じように、シャドーイングします 。例えば:
36
+ パターンには一つ落とし穴があります。新しい束縛を導入する他の構文と同様、パターンはシャドーイングをします 。例えば:
37
37
38
38
``` rust
39
39
let x = 'x' ;
@@ -47,7 +47,7 @@ println!("x: {}", x)
47
47
```
48
48
49
49
<!-- This prints:-->
50
- これの結果は以下のようになります:
50
+ これは以下のように出力します。
51
51
52
52
``` text
53
53
x: c c: c
57
57
<!-- In other words, `x =>` matches the pattern and introduces a new binding named
58
58
`x` that’s in scope for the match arm. Because we already have a binding named
59
59
`x`, this new `x` shadows it. -->
60
- 別の言い方をすると、 ` x => ` はパターンへのマッチだけでなく 、マッチの腕内で有効な ` x ` という名前の束縛を導入します。既に ` x ` は束縛されていたので、この新しい ` x ` はそれを覆い隠します 。
60
+ 別の言い方をすると、 ` x => ` は値をパターンにマッチさせ 、マッチの腕内で有効な ` x ` という名前の束縛を導入します。既に ` x ` という束縛が存在していたので、新たに導入した ` x ` は、その古い ` x ` をシャドーイングします 。
61
61
62
62
<!-- # Multiple patterns -->
63
63
# 複式パターン
64
64
65
65
<!-- You can match multiple patterns with `|`: -->
66
- ` | ` を使うと、複式パターンが導入できます :
66
+ ` | ` を使うと、複数のパターンにマッチさせることができます :
67
67
68
68
69
69
``` rust
@@ -80,11 +80,11 @@ match x {
80
80
これは、 ` one or two ` を出力します。
81
81
82
82
<!-- # Destructuring -->
83
- # デストラクチャリング
83
+ # 分配束縛
84
84
85
85
<!-- If you have a compound data type, like a [`struct`][struct], you can destructure it
86
86
inside of a pattern: -->
87
- 例えば [ ` struct ` ] [ struct ] のような複合データ型を作成したいとき、パターン内でデータを分解することができます 。
87
+ [ ` struct ` ] [ struct ] のような複合データ型が存在するとき、パターン内でその値を分解することができます 。
88
88
89
89
``` rust
90
90
struct Point {
@@ -118,7 +118,7 @@ match origin {
118
118
```
119
119
120
120
<!-- If we only care about some of the values, we don’t have to give them all names: -->
121
- 値の一部だけを扱いたい場合は、値の全てに名前を付ける必要はありません 。
121
+ 値の一部にだけ興味がある場合は、値のすべてに名前を付ける必要はありません 。
122
122
123
123
``` rust
124
124
struct Point {
@@ -137,7 +137,7 @@ match origin {
137
137
これは ` x is 0 ` を出力します。
138
138
139
139
<!-- You can do this kind of match on any member, not just the first:-->
140
- どのメンバに対してもこの種のマッチを行うことができます。たとえ最初ではなくても:
140
+ 最初のメンバだけでなく、 どのメンバに対してもこの種のマッチを行うことができます。
141
141
142
142
``` rust
143
143
struct Point {
@@ -157,7 +157,7 @@ match origin {
157
157
158
158
<!-- This ‘destructuring’ behavior works on any compound data type, like
159
159
[tuples][tuples] or [enums][enums]. -->
160
- この「デストラクチャリング (destructuring)」 と呼ばれる振る舞いは、 [ タプル] [ tuples ] や [ 列挙型] [ enums ] のような、複合データ型で使用できます 。
160
+ この「分配束縛」 (destructuring) と呼ばれる振る舞いは、 [ タプル] [ tuples ] や [ 列挙型] [ enums ] のような、任意の複合データ型で使用できます 。
161
161
162
162
[ tuples ] : primitive-types.html#tuples
163
163
[ enums ] : enums.html
@@ -169,7 +169,7 @@ match origin {
169
169
パターン内の型や値を無視するために ` _ ` を使うことができます。
170
170
171
171
<!-- For example, here’s a `match` against a `Result<T, E>`: -->
172
- 例として、 ` Result<T, E> ` に対して ` match ` を適用してみましょう :
172
+ 例として、 ` Result<T, E> ` に対して ` match ` をしてみましょう :
173
173
174
174
``` rust
175
175
# let some_value : Result <i32 , & 'static str > = Err (" There was an error" );
@@ -182,11 +182,11 @@ match some_value {
182
182
<!-- In the first arm, we bind the value inside the `Ok` variant to `value`. But
183
183
in the `Err` arm, we use `_` to disregard the specific error, and just print
184
184
a general error message. -->
185
- 最初の部分では ` Ok ` ヴァリアント内の値を ` value ` に結びつけています 。しかし ` Err ` 部分では、特定のエラーを避けて、標準的なエラーメッセージを表示するために ` _ ` を使っています。
185
+ 最初の部分では ` Ok ` ヴァリアント内の値に ` value ` を束縛しています 。しかし ` Err ` 部分では、ヴァリアント内のエラー情報を無視して一般的なエラーメッセージを表示するために ` _ ` を使っています。
186
186
187
187
<!-- `_` is valid in any pattern that creates a binding. This can be useful to
188
188
ignore parts of a larger structure: -->
189
- ` _ ` は束縛を伴うどんなパターンにおいても有効です。これは大きな構造の一部分を無視する際に有用です 。
189
+ ` _ ` は束縛を導入するどのようなパターンにおいても有効です。これは大きな構造の一部を無視する際に有用です 。
190
190
191
191
``` rust
192
192
fn coordinate () -> (i32 , i32 , i32 ) {
@@ -200,7 +200,7 @@ let (x, _, z) = coordinate();
200
200
201
201
<!-- Here, we bind the first and last element of the tuple to `x` and `z`, but
202
202
ignore the middle element. -->
203
- ここでは、タプルの最初と最後の要素を ` x ` と ` z ` に結びつけています 。
203
+ ここでは、タプルの最初と最後の要素に ` x ` と ` z ` を束縛します 。
204
204
205
205
<!-- Similarly, you can use `..` in a pattern to disregard multiple values. -->
206
206
同様に ` .. ` でパターン内の複数の値を無視することができます。
@@ -226,7 +226,7 @@ match x {
226
226
# ref と ref mut
227
227
228
228
<!-- If you want to get a [reference][ref], use the `ref` keyword:-->
229
- もし [ リファレンス ] [ ref ] を取得したいときは ` ref ` キーワードを使いましょう。
229
+ [ 参照 ] [ ref ] を取得したいときは ` ref ` キーワードを使いましょう。
230
230
231
231
``` rust
232
232
let x = 5 ;
@@ -244,7 +244,7 @@ match x {
244
244
<!-- Here, the `r` inside the `match` has the type `&i32`. In other words, the `ref`
245
245
keyword _creates_ a reference, for use in the pattern. If you need a mutable
246
246
reference, `ref mut` will work in the same way: -->
247
- ここで ` match ` 内の ` r ` は ` &i32 ` 型を持っています。言い換えると ` ref ` キーワードがリファレンスを _ 作ります _ 。
247
+ ここで ` match ` 内の ` r ` は ` &i32 ` 型を持っています。言い換えると、 ` ref ` キーワードはパターン内で使う参照を _ 作り出します _ 。ミュータブルな参照が必要な場合は、同様に ` ref mut ` を使います 。
248
248
249
249
``` rust
250
250
let mut x = 5 ;
@@ -255,10 +255,10 @@ match x {
255
255
```
256
256
257
257
<!-- # Ranges -->
258
- # レンジ
258
+ # 範囲
259
259
260
260
<!-- You can match a range of values with `...`: -->
261
- ` ... ` で値のレンジのマッチを行うことができます :
261
+ ` ... ` で値の範囲をマッチさせることができます :
262
262
263
263
``` rust
264
264
let x = 1 ;
@@ -273,7 +273,7 @@ match x {
273
273
これは ` one through five ` を出力します。
274
274
275
275
<!-- Ranges are mostly used with integers and `char`s: -->
276
- レンジは大体 、整数か ` char ` 型で使われます:
276
+ 範囲は多くの場合 、整数か ` char ` 型で使われます:
277
277
278
278
``` rust
279
279
let x = '💅' ;
@@ -292,7 +292,7 @@ match x {
292
292
# 束縛
293
293
294
294
<!-- You can bind values to names with `@`: -->
295
- ` @ ` で値を名前と結びつけることができます 。
295
+ ` @ ` で値に名前を束縛することができます 。
296
296
297
297
``` rust
298
298
let x = 1 ;
@@ -306,7 +306,7 @@ match x {
306
306
<!-- This prints `got a range element 1`. This is useful when you want to
307
307
do a complicated match of part of a data structure: -->
308
308
これは ` got a range element 1 ` を出力します。
309
- データ構造の一部に対する複雑なマッチが欲しいときに有用です :
309
+ データ構造の一部に対して複雑なマッチングをしたいときに有用です :
310
310
311
311
``` rust
312
312
#[derive(Debug )]
@@ -323,11 +323,11 @@ match x {
323
323
```
324
324
325
325
<!-- This prints `Some("Steve")`: we’ve bound the inner `name` to `a`.-->
326
- これは ` Some("Steve") ` を出力します。内側の ` name ` を ` a ` に結びつけます 。
326
+ これは ` Some("Steve") ` を出力します。内側の ` name ` の値への参照に ` a ` を束縛します 。
327
327
328
328
<!-- If you use `@` with `|`, you need to make sure the name is bound in each part
329
329
of the pattern: -->
330
- もし ` | ` で ` @ ` を使うときは、パターンのそれぞれの部分が名前と結びついているか確認する必要があります :
330
+ ` @ ` を ` | ` と組み合わせて使う場合は、それぞれのパターンで同じ名前が束縛されるようにする必要があります :
331
331
332
332
``` rust
333
333
let x = 5 ;
@@ -363,7 +363,7 @@ match x {
363
363
これは ` Got an int! ` を出力します。
364
364
365
365
<!-- If you’re using `if` with multiple patterns, the `if` applies to both sides:-->
366
- 複式パターンで ` if ` を使うと、 ` if ` は両方に適用されます :
366
+ 複式パターンで ` if ` を使うと、 ` if ` は ` | ` の両側に適用されます :
367
367
368
368
``` rust
369
369
let x = 4 ;
@@ -377,7 +377,7 @@ match x {
377
377
378
378
<!-- This prints `no`, because the `if` applies to the whole of `4 | 5`, and not to
379
379
just 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 ` 節は以下のように振舞います:
381
381
382
382
``` text
383
383
(4 | 5) if y => ...
@@ -395,7 +395,7 @@ just the `5`. In other words, the precedence of `if` behaves like this: -->
395
395
396
396
<!-- Whew! That’s a lot of different ways to match things, and they can all be
397
397
mixed and matched, depending on what you’re doing: -->
398
- ふう、マッチには様々な方法があるのですね。やりたいこと次第で 、それらを混ぜてマッチさせることもできます:
398
+ ふう、マッチには様々な方法があるのですね。やりたいことに応じて 、それらを混ぜてマッチさせることもできます:
399
399
400
400
``` rust,ignore
401
401
match x {
0 commit comments